From 803f1bc25ae377bc4094137b67b651906fd59ef9 Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Fri, 1 Dec 2023 15:41:20 +0100 Subject: [PATCH 1/2] Fix labeling of the command palette. --- .../commands/src/components/command-menu.js | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/commands/src/components/command-menu.js b/packages/commands/src/components/command-menu.js index e844fce7bae73c..5dacc75b102c83 100644 --- a/packages/commands/src/components/command-menu.js +++ b/packages/commands/src/components/command-menu.js @@ -32,6 +32,8 @@ import { Icon, search as inputIcon } from '@wordpress/icons'; */ import { store as commandsStore } from '../store'; +const inputLabel = __( 'Search for commands' ); + function CommandMenuLoader( { name, search, hook, setLoader, close } ) { const { isLoading, commands = [] } = hook( { search } ) ?? {}; useEffect( () => { @@ -176,7 +178,7 @@ function CommandInput( { isOpen, search, setSearch } ) { ref={ commandMenuInput } value={ search } onValueChange={ setSearch } - placeholder={ __( 'Search for commands' ) } + placeholder={ inputLabel } aria-activedescendant={ selectedItemId } icon={ search } /> @@ -195,6 +197,7 @@ export function CommandMenu() { ); const { open, close } = useDispatch( commandsStore ); const [ loaders, setLoaders ] = useState( {} ); + const commandListRef = useRef(); useEffect( () => { registerShortcut( { @@ -208,6 +211,16 @@ export function CommandMenu() { } ); }, [ registerShortcut ] ); + // Temporary fix for the suggestions Listbox labeling. + // See https://github.com/pacocoursey/cmdk/issues/196 + useEffect( () => { + commandListRef.current?.removeAttribute( 'aria-labelledby' ); + commandListRef.current?.setAttribute( + 'aria-label', + __( 'Command suggestions' ) + ); + }, [ commandListRef.current ] ); + useShortcut( 'core/commands', /** @type {import('react').KeyboardEventHandler} */ @@ -265,12 +278,10 @@ export function CommandMenu() { overlayClassName="commands-command-menu__overlay" onRequestClose={ closeAndReset } __experimentalHideHeader + contentLabel={ __( 'Command palette' ) } >
- +
- + { search && ! isLoading && ( { __( 'No results found.' ) } From d1d5cd6b00358f7b1adb15d9172bf4c3299cc735 Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Mon, 4 Dec 2023 16:36:50 +0100 Subject: [PATCH 2/2] Try removing nested Listboxes. --- .../commands/src/components/command-menu.js | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/packages/commands/src/components/command-menu.js b/packages/commands/src/components/command-menu.js index 5dacc75b102c83..fe232fe2d3979d 100644 --- a/packages/commands/src/components/command-menu.js +++ b/packages/commands/src/components/command-menu.js @@ -46,34 +46,29 @@ function CommandMenuLoader( { name, search, hook, setLoader, close } ) { return ( <> - - { commands.map( ( command ) => ( - command.callback( { close } ) } - id={ command.name } + { commands.map( ( command ) => ( + command.callback( { close } ) } + id={ command.name } + > + - - { command.icon && } - - - - - - ) ) } - + { command.icon && } + + + + + + ) ) } ); }