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

Fix : Duplicative link control label and placeholder #66329

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

Vrishabhsk
Copy link
Contributor

What?

  • Prevent duplicate text for label and placeholder props of LinkControlSearchInput component

Why?

How?

  • Add label prop to LinkControlSearchInput component
  • The label prop get its value from searchInputLabel prop set for LinkControl component

@Vrishabhsk Vrishabhsk requested a review from getdave as a code owner October 22, 2024 13:56
Copy link

github-actions bot commented Oct 22, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Vrishabhsk <[email protected]>
Co-authored-by: getdave <[email protected]>
Co-authored-by: jeryj <[email protected]>
Co-authored-by: mirka <[email protected]>
Co-authored-by: richtabor <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@getdave getdave added [Type] Regression Related to a regression in the latest release [Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) labels Oct 24, 2024
Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

I appreciate the follow up here.

My main concern is that the new placeholder seems to just repeat the same text as the label. That seems superflous.

Image

I would suggest we can remove the placeholder (by default).

MDN suggests the following definition of placeholder:

The placeholder text should provide a brief hint to the user as to the expected type of data that should be entered into the control.

Therefore using the word Search isn't terrible useful to the user as it's not an example of the type of input.

I thought about potential examples we could use. The two types of input are either:

  • A search string for an entity (e.g. a Post or Page) such as Sample Page.
  • A search for a URL such as www.example.com.

However the problem is that because it's in the @wordpress/block-editor package, this control can be used outside of WordPress. This rules out any WordPress-specific examples such as www.wordpress.org or Sample Page.

As a result Im now leaning towards defaulting placeholder to null and requiring that the specific implementation defines the placeholder. So when being used in a WP context the placeholder could be set.

Thanks again for your work here 👍

Copy link
Contributor

@jeryj jeryj left a comment

Choose a reason for hiding this comment

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

@mirka Should the <InputBase/> implement logic to force the label to match the placeholder if hideLabelFromVision is true?

That seems like it would prevent a lot of bugs and force some built-in a11y.

Comment on lines 117 to 126
return (
<div className="block-editor-link-control__search-input-container">
<URLInput
disableSuggestions={ currentLink?.url === value }
label={ inputLabel }
label={ label ?? __( 'Search or type URL' ) }
hideLabelFromVision={ hideLabelFromVision }
className={ className }
value={ value }
onChange={ onInputChange }
placeholder={ inputLabel }
placeholder={ placeholder }
Copy link
Contributor

Choose a reason for hiding this comment

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

From the Why section of the PR that introduced the duplicative change, the rationale is that if there is no visible label then the placeholder text must match the label. It doesn't look like <InputBase /> handles this for us, so we could do it here:

  1. Set a const for the inputLabel above this block: const inputLabel = label ?? __( 'Search or type URL' )
  2. Apply the label: label={ inputLabel }
  3. Check for hideLabelFromVision before applying the placeholder: placeholder={ hideLabelFromVision ? inputLabel : placeholder }

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 We don't want to end up in a situation where we have the label and placeholder showing the same thing. That's the principle bug we have to address in this PR. Visual reference:

Image

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup - hopefully the sample code I added will:

  • Not have the placeholder and label match unless the consumer passes strings that match.
  • Force the placeholder to match the label only if hideLabelFromVision is true and we would want the placeholder and label to match.

@mirka
Copy link
Member

mirka commented Oct 25, 2024

Should the <InputBase/> implement logic to force the label to match the placeholder if hideLabelFromVision is true?

For a low-level component, this seems a bit too heavy-handed for me since hideLabelFromVision doesn't necessarily mean that the input has no visible label whatsoever. It could be that the consumer wants to hide the default-styled label, and replace it with a custom-styled one.

Though, I think we can start by including this accessibility guideline in the best practices section of the component docs that we're working on improving right now (for example in #66000).

@getdave getdave requested a review from jeryj November 4, 2024 12:42
@Vrishabhsk Vrishabhsk requested a review from getdave December 27, 2024 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) [Type] Regression Related to a regression in the latest release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicative link control label and placeholder
4 participants