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

ClipboardCopy only needs aria-label when empty #1244

Conversation

neall
Copy link
Contributor

@neall neall commented Jul 29, 2022

We were requiring aria-label on ClipboardCopy in all cases, but when the component already contains suitable text this is not recommended.

This changes when we validate the presence of aria-label. At instantiation time the component doesn't know if it will be rendered with a block, so we check at render time instead.

Fixes #1081

@neall neall requested review from a team and hectahertz July 29, 2022 17:21
@changeset-bot
Copy link

changeset-bot bot commented Jul 29, 2022

🦋 Changeset detected

Latest commit: 88bb2d4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/view-components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@neall neall force-pushed the do-not-require-aria-label-on-clipboard-copy-with-content branch from cc44bb0 to ada775e Compare July 29, 2022 17:25
@@ -34,10 +34,16 @@ def initialize(value: nil, **system_arguments)
@system_arguments[:value] = value if value.present?
end

# :nodoc:
def render_in(*args, &block)
validate_aria_label unless block_given?
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I'm not sure checking the presence of a block is the right approach here. The component could ostensibly be passed an empty block, or someday have slots that must be defined in the block. What would you think about something like:

def before_render
  validate_aria_label if content.blank?
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They can always give some content that is not suitable for screen readers, but explicitly checking for blank sounds good. before_render also sounds like a better place for this check than hooking into render_in as well.

@neall neall force-pushed the do-not-require-aria-label-on-clipboard-copy-with-content branch 2 times, most recently from 38faf06 to c8a1fb6 Compare July 29, 2022 17:49
We were requiring `aria-label` on ClipboardCopy in all cases, but when
the component already contains suitable text this is not recommended.

This changes when we validate the presence of `aria-label`. At
instantiation time the component doesn't know if it will be rendered
with a block, so we check at render time instead.

Fixes primer#1081
I was just checking for a block to decide if ClipboardCopy needed an
aria-label. But @camertron suggested that checking for blank content
would be better, and I think the code is nicer as well.
@neall neall force-pushed the do-not-require-aria-label-on-clipboard-copy-with-content branch from c8a1fb6 to 0a5cb86 Compare July 29, 2022 17:58
An explicit nil tests just as well while satisfying the linter.
@neall neall force-pushed the do-not-require-aria-label-on-clipboard-copy-with-content branch from 69d09d1 to 88bb2d4 Compare July 29, 2022 18:59
@jonrohan jonrohan merged commit 91a6d2d into primer:main Aug 1, 2022
@primer-css primer-css mentioned this pull request Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ClipboardCopy component requires aria-label even when text is set
3 participants