Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match visible label of search inputs with their actual label. #65458

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -163,7 +163,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
Loading