Skip to content

Commit

Permalink
Fix Dropdown/DropdownMenu toggle closing in all UAs (#31170)
Browse files Browse the repository at this point in the history
* Make root element of Dropdown focusable

* Update snapshots

* Remove disabled toggle workaround in Template Part block
  • Loading branch information
stokesman authored Sep 14, 2021
1 parent 0acf443 commit 8714f66
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
>
<div
className="components-dropdown components-circular-option-picker__dropdown-link-action"
tabIndex="-1"
>
<button
aria-describedby={null}
Expand Down
3 changes: 0 additions & 3 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ export default function TemplatePartEdit( {
<ToolbarButton
aria-expanded={ isOpen }
onClick={ onToggle }
// Disable when open to prevent odd FireFox bug causing reopening.
// As noted in https://github.com/WordPress/gutenberg/pull/24990#issuecomment-689094119 .
disabled={ isOpen }
>
{ __( 'Replace' ) }
</ToolbarButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ exports[`ColorPalette Dropdown should render it correctly 1`] = `
>
<div
className="components-dropdown components-circular-option-picker__dropdown-link-action"
tabIndex="-1"
>
<ForwardRef(Button)
aria-expanded={false}
Expand Down Expand Up @@ -545,6 +546,7 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
>
<div
className="components-dropdown components-circular-option-picker__dropdown-link-action"
tabIndex="-1"
>
<ForwardRef(Button)
aria-expanded={false}
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export default function Dropdown( {
<div
className={ classnames( 'components-dropdown', className ) }
ref={ containerRef }
// Some UAs focus the closest focusable parent when the toggle is
// clicked. Making this div focusable ensures such UAs will focus
// it and `closeIfFocusOutside` can tell if the toggle was clicked.
tabIndex="-1"
>
{ renderToggle( args ) }
{ isOpen && (
Expand Down

0 comments on commit 8714f66

Please sign in to comment.