Skip to content

Commit

Permalink
a11y: return focus to parent button on reset
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshbhutkar committed Feb 3, 2025
1 parent c1dcacc commit 0456fd8
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Composite,
Tooltip,
} from '@wordpress/components';
import { useMemo } from '@wordpress/element';
import { useMemo, useRef } from '@wordpress/element';
import { shadow as shadowIcon, Icon, check, reset } from '@wordpress/icons';

/**
Expand Down Expand Up @@ -135,10 +135,13 @@ export function ShadowPopover( { shadow, onShadowChange, settings } ) {

function renderShadowToggle( shadow, onShadowChange ) {
return ( { onToggle, isOpen } ) => {
const shadowButtonRef = useRef( undefined );

const toggleProps = {
onClick: onToggle,
className: clsx( { 'is-open': isOpen } ),
'aria-expanded': isOpen,
ref: shadowButtonRef,
};

const removeButtonProps = {
Expand All @@ -147,6 +150,8 @@ function renderShadowToggle( shadow, onShadowChange ) {
onToggle();
}
onShadowChange( undefined );
// Return focus to parent button.
shadowButtonRef.current?.focus();
},
className: clsx(
'block-editor-global-styles__shadow-editor__remove-button',
Expand Down

0 comments on commit 0456fd8

Please sign in to comment.