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

Visually hide the LinkControl initial/results heading #50977

Merged
merged 4 commits into from
May 31, 2023
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 @@ -8,7 +8,6 @@ import { VisuallyHidden } from '@wordpress/components';
* External dependencies
*/
import classnames from 'classnames';
import { createElement, Fragment } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -53,25 +52,16 @@ export default function LinkControlSearchResults( {
// 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
? __( 'Recently updated' )
? __( 'Suggestions' )
: sprintf(
/* translators: %s: search term. */
__( 'Search results for "%s"' ),
currentInputValue
);

// VisuallyHidden rightly doesn't accept custom classNames
// so we conditionally render it as a wrapper to visually hide the label
// when that is required.
const searchResultsLabel = createElement(
isInitialSuggestions ? Fragment : VisuallyHidden,
{}, // Empty props.
<span
className="block-editor-link-control__search-results-label"
id={ searchResultsLabelId }
>
const searchResultsLabel = (
<VisuallyHidden id={ searchResultsLabelId }>
{ labelText }
</span>
</VisuallyHidden>
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ $preview-image-height: 140px;
}
}

.block-editor-link-control__search-results-label {
padding: $grid-unit-20 $grid-unit-40 0;
display: block;
font-weight: 600;
}

.block-editor-link-control__search-results {
margin: 0;
padding: $grid-unit-20 * 0.5 $grid-unit-20 $grid-unit-20 * 0.5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ describe( 'Default search suggestions', () => {

expect(
await screen.findByRole( 'listbox', {
name: 'Recently updated',
name: 'Suggestions',
} )
).toBeVisible();

Expand Down Expand Up @@ -991,7 +991,7 @@ describe( 'Default search suggestions', () => {
expect( searchInput ).toHaveValue( '' );

const initialResultsList = await screen.findByRole( 'listbox', {
name: 'Recently updated',
name: 'Suggestions',
} );

expect(
Expand All @@ -1008,7 +1008,7 @@ describe( 'Default search suggestions', () => {
const searchInput = screen.getByRole( 'combobox', { name: 'URL' } );

const searchResultsField = screen.queryByRole( 'listbox', {
name: 'Recently updated',
name: 'Suggestions',
} );

expect( searchResultsField ).not.toBeInTheDocument();
Expand Down Expand Up @@ -1598,7 +1598,7 @@ describe( 'Selecting links', () => {

expect(
await screen.findByRole( 'listbox', {
name: 'Recently updated',
name: 'Suggestions',
} )
).toBeVisible();

Expand All @@ -1610,7 +1610,7 @@ describe( 'Selecting links', () => {

const searchResultElements = within(
screen.getByRole( 'listbox', {
name: 'Recently updated',
name: 'Suggestions',
} )
).getAllByRole( 'option' );

Expand Down