Skip to content

Commit

Permalink
Shadows: Improve design and a11y of remove button (#67705)
Browse files Browse the repository at this point in the history
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: juanfra <[email protected]>
Co-authored-by: madhusudhand <[email protected]>
Co-authored-by: mikachan <[email protected]>
Co-authored-by: jasmussen <[email protected]>
  • Loading branch information
6 people authored Dec 10, 2024
1 parent 55075af commit 8884fb8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
reset,
moreVertical,
} from '@wordpress/icons';
import { useState, useMemo, useEffect } from '@wordpress/element';
import { useState, useMemo, useEffect, useRef } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -300,6 +300,7 @@ function ShadowsPreview( { shadow } ) {
}

function ShadowEditor( { shadow, onChange } ) {
const addShadowButtonRef = useRef();
const shadowParts = useMemo( () => getShadowParts( shadow ), [ shadow ] );

const onChangeShadowPart = ( index, part ) => {
Expand All @@ -314,6 +315,7 @@ function ShadowEditor( { shadow, onChange } ) {

const onRemoveShadowPart = ( index ) => {
onChange( shadowParts.filter( ( p, i ) => i !== index ).join( ', ' ) );
addShadowButtonRef.current.focus();
};

return (
Expand All @@ -334,6 +336,7 @@ function ShadowEditor( { shadow, onChange } ) {
onClick={ () => {
onAddShadowPart();
} }
ref={ addShadowButtonRef }
/>
</FlexItem>
</HStack>
Expand Down Expand Up @@ -393,28 +396,24 @@ function ShadowItem( { shadow, onChange, canRemove, onRemove } ) {
};

return (
<HStack align="center" justify="flex-start" spacing={ 0 }>
<FlexItem style={ { flexGrow: 1 } }>
<Button
__next40pxDefaultSize
icon={ shadowIcon }
{ ...toggleProps }
>
{ shadowObj.inset
? __( 'Inner shadow' )
: __( 'Drop shadow' ) }
</Button>
</FlexItem>
<>
<Button
__next40pxDefaultSize
icon={ shadowIcon }
{ ...toggleProps }
>
{ shadowObj.inset
? __( 'Inner shadow' )
: __( 'Drop shadow' ) }
</Button>
{ canRemove && (
<FlexItem>
<Button
__next40pxDefaultSize
icon={ reset }
{ ...removeButtonProps }
/>
</FlexItem>
<Button
size="small"
icon={ reset }
{ ...removeButtonProps }
/>
) }
</HStack>
</>
);
} }
renderContent={ () => (
Expand Down
40 changes: 27 additions & 13 deletions packages/edit-site/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,34 @@

.edit-site-global-styles__shadow-editor__dropdown {
width: 100%;
position: relative;
}

.edit-site-global-styles__shadow-editor__dropdown-toggle,
.edit-site-global-styles__shadow-editor__remove-button {
width: 100%;
height: auto;
padding-top: $grid-unit;
padding-bottom: $grid-unit;
text-align: left;
border-radius: inherit;

&.is-open {
background: $gray-100;
color: var(--wp-admin-theme-color);
}
.edit-site-global-styles__shadow-editor__dropdown-toggle {
width: 100%;
height: auto;
padding-top: $grid-unit;
padding-bottom: $grid-unit;
text-align: left;
border-radius: inherit;

&.is-open {
background: $gray-100;
color: var(--wp-admin-theme-color);
}
}

.edit-site-global-styles__shadow-editor__remove-button {
position: absolute;
right: $grid-unit;
top: $grid-unit;
opacity: 0;

.edit-site-global-styles__shadow-editor__dropdown-toggle:hover + &,
&:focus,
&:hover {
border: none;
opacity: 1;
}
}

Expand Down

0 comments on commit 8884fb8

Please sign in to comment.