Skip to content

Commit

Permalink
Match visible label of search inputs with their actual label. (WordPr…
Browse files Browse the repository at this point in the history
…ess#65458)

* Match visible label of search inputs with their actual label.

* Adjust more tests.

* Adjust more tests.

Co-authored-by: afercia <afercia@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
  • Loading branch information
4 people authored and karthick-murugan committed Nov 13, 2024
1 parent 7fff8a4 commit a547a00
Show file tree
Hide file tree
Showing 29 changed files with 136 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function PatternsExplorerSearch( { searchValue, setSearchValue } ) {
__nextHasNoMarginBottom
onChange={ setSearchValue }
value={ searchValue }
label={ __( 'Search for patterns' ) }
label={ __( 'Search' ) }
placeholder={ __( 'Search' ) }
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function InserterMenu(
setFilterValue( value );
} }
value={ filterValue }
label={ __( 'Search for blocks and patterns' ) }
label={ __( 'Search' ) }
placeholder={ __( 'Search' ) }
/>
{ !! delayedFilterValue && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default function QuickInserter( {
onChange={ ( value ) => {
setFilterValue( value );
} }
label={ __( 'Search for blocks and patterns' ) }
label={ __( 'Search' ) }
placeholder={ __( 'Search' ) }
/>
) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* WordPress dependencies
*/
import { useInstanceId } from '@wordpress/compose';
import { forwardRef, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

Expand Down Expand Up @@ -58,7 +57,6 @@ const LinkControlSearchInput = forwardRef(
? fetchSuggestions || genericSearchHandler
: noopSearchHandler;

const instanceId = useInstanceId( LinkControlSearchInput );
const [ focusedSuggestion, setFocusedSuggestion ] = useState();

/**
Expand All @@ -76,7 +74,6 @@ const LinkControlSearchInput = forwardRef(
const handleRenderSuggestions = ( props ) =>
renderSuggestions( {
...props,
instanceId,
withCreateSuggestion,
createSuggestionButtonText,
suggestionsQuery,
Expand Down Expand Up @@ -116,16 +113,18 @@ const LinkControlSearchInput = forwardRef(
}
};

const inputLabel = placeholder ?? __( 'Search or type URL' );

return (
<div className="block-editor-link-control__search-input-container">
<URLInput
disableSuggestions={ currentLink?.url === value }
label={ __( 'Link' ) }
label={ inputLabel }
hideLabelFromVision={ hideLabelFromVision }
className={ className }
value={ value }
onChange={ onInputChange }
placeholder={ placeholder ?? __( 'Search or type URL' ) }
placeholder={ inputLabel }
__experimentalRenderSuggestions={
showSuggestions ? handleRenderSuggestions : null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { VisuallyHidden, MenuGroup } from '@wordpress/components';
import { MenuGroup } from '@wordpress/components';

/**
* External dependencies
Expand All @@ -17,7 +17,6 @@ import LinkControlSearchItem from './search-item';
import { CREATE_TYPE, LINK_ENTRY_TYPES } from './constants';

export default function LinkControlSearchResults( {
instanceId,
withCreateSuggestion,
currentInputValue,
handleSuggestionClick,
Expand Down Expand Up @@ -47,30 +46,20 @@ export default function LinkControlSearchResults( {
// If the query has a specified type, then we can skip showing them in the result. See #24839.
const shouldShowSuggestionsTypes = ! suggestionsQuery?.type;

// According to guidelines aria-label should be added if the label
// itself is not visible.
// See: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role
const searchResultsLabelId = `block-editor-link-control-search-results-label-${ instanceId }`;
const labelText = isInitialSuggestions
? __( 'Suggestions' )
: sprintf(
/* translators: %s: search term. */
__( 'Search results for "%s"' ),
currentInputValue
);
const searchResultsLabel = (
<VisuallyHidden id={ searchResultsLabelId }>
{ labelText }
</VisuallyHidden>
);

return (
<div className="block-editor-link-control__search-results-wrapper">
{ searchResultsLabel }
<div
{ ...suggestionsListProps }
className={ resultsListClasses }
aria-labelledby={ searchResultsLabelId }
aria-label={ labelText }
>
<MenuGroup>
{ suggestions.map( ( suggestion, index ) => {
Expand Down
Loading

0 comments on commit a547a00

Please sign in to comment.