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

Improve block search input's accessible name and placeholder #28393

Merged
merged 4 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ function InserterMenu( {
setFilterValue( value );
} }
value={ filterValue }
placeholder={ __( 'Search' ) }
label={ __( 'Search' ) }
placeholder={ __( 'Search for blocks and patterns' ) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can also search for reusable blocks, not sure if it counts as "blocks".

The placeholder change seems like a design decision, so let's try to get some opinions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the ping. You can indeed search for blocks, patterns, and reusable blocks.

However for brevity, I would think it okay to lump in reusable blocks with blocks, for a few reasons:

  • Reusable blocks only show up when you first create one.
  • When that happens, there's also a separate tab for it.

So in the name of brevity, this seems okay to try 👍 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I don't like personally is that sometimes there's no patterns... and "Search" is more generic. I don't want us to introduce conditions (so performance impact calling selectors) just to tweak the placeholder accurately. Isn't there another solution while still keeping the "Search" placeholder?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phrase-wise, plain old "Search" would be fine for me also. I'll defer if there's a technical underpinning to the change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexstine suggested "Search for blocks" on #26938 (comment). Since patterns are also collections of blocks and the button label is "Add block", it sounds generic enough, but still more descriptive than just "Search".

/>
{ !! filterValue && (
<InserterSearchResults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export default function QuickInserter( {
onChange={ ( value ) => {
setFilterValue( value );
} }
placeholder={ __( 'Search for a block' ) }
label={ __( 'Search' ) }
placeholder={ __( 'Search for blocks and patterns' ) }
/>
) }

Expand Down
10 changes: 8 additions & 2 deletions packages/block-editor/src/components/inserter/search-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import { VisuallyHidden, Button } from '@wordpress/components';
import { Icon, search, closeSmall } from '@wordpress/icons';
import { useRef } from '@wordpress/element';

function InserterSearchForm( { className, onChange, value, placeholder } ) {
function InserterSearchForm( {
className,
onChange,
value,
label,
placeholder,
} ) {
const instanceId = useInstanceId( InserterSearchForm );
const searchInput = useRef();

Expand All @@ -27,7 +33,7 @@ function InserterSearchForm( { className, onChange, value, placeholder } ) {
as="label"
htmlFor={ `block-editor-inserter__search-${ instanceId }` }
>
{ placeholder }
{ label || placeholder }
</VisuallyHidden>
<input
ref={ searchInput }
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/specs/widgets/adding-widgets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ describe( 'Widgets screen', () => {

// TODO: The query should be rewritten with role and label.
const inserterSearchBox = await page.waitForSelector(
'input[type="search"][placeholder="Search for a block"]'
'input[type="search"][placeholder="Search for blocks and patterns"]'
);
expect(
await inserterSearchBox.evaluate(
Expand Down