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

2777 Add restProps to IconButton … #2791

Merged
merged 10 commits into from
Dec 14, 2022

Conversation

emilyuhde
Copy link
Contributor

@emilyuhde emilyuhde commented Dec 12, 2022

… and use it to pass aria-labels down to the button element where it's used in other UI components

@pngwn

Description

Closes: #2777

Checklist:

  • I have performed a self-review of my own code
  • I have added a short summary of my change to the CHANGELOG.md
  • My code follows the style guidelines of this project
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

A note about the CHANGELOG

Hello 👋 and thank you for contributing to Gradio!

All pull requests must update the change log located in CHANGELOG.md, unless the pull request is labeled with the "no-changelog-update" label.

Please add a brief summary of the change to the Upcoming Release > Full Changelog section of the CHANGELOG.md file and include
a link to the PR (formatted in markdown) and a link to your github profile (if you like). For example, "* Added a cool new feature by [@myusername](link-to-your-github-profile) in [PR 11111](https://github.com/gradio-app/gradio/pull/11111)".

If you would like to elaborate on your change further, feel free to include a longer explanation in the other sections.
If you would like an image/gif/video showcasing your feature, it may be best to edit the CHANGELOG file using the
GitHub web UI since that lets you upload files directly via drag-and-drop.

…to the button element where it's used in other UI components
@emilyuhde
Copy link
Contributor Author

emilyuhde commented Dec 12, 2022

Just a note on the changelog, my IDE is set to automatically remove trailing whitespace from files on save, hence all the changes. I can try to revert that if you want to keep them.

Also, please let me know if there's something I need to do to get these hooked up for translations!

Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

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

Hi @emilyuhde. Thanks for this!

Just left some comments around the use of $$restProps. When that is adjusted we should be good to go.

This PR will also need to add an item to the CHANGELOG.md.

Under the Upcoming Release heading you need to add something like the following

## Bug Fixes

* Add aria-labels to button icons, improving accessibility by [@emilyuhde](https://github.com/emilyuhde) in [in PR2791](https://github.com/gradio-app/gradio/pull/2791)

Don't worry too much about the conflicts. When this PR is ready, I can resolve those.

@@ -6,6 +6,7 @@
<button
on:click
class="text-gray-500 bg-white/90 h-5 w-5 flex items-center justify-center rounded shadow-sm hover:shadow-xl hover:ring-1 ring-inset ring-gray-200 z-10 dark:bg-gray-900 dark:ring-gray-600"
{...$$restProps}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a huge fan of $$restProps because it is hard to work out what is being passed down and results in code that isn't as well optimised (by the Svelte compiler). It is useful when we don't know the props at build time, but that isn't the case here.

Since we know these values ahead of time, we can just define a label prop in this component (export let label) and set that as the aria-label explicitly.

@@ -7,9 +7,10 @@
</script>

<div class="z-50 top-2 right-2 justify-end flex gap-1 absolute">
<IconButton Icon={Undo} on:click={() => dispatch("undo")} />
<IconButton Icon={Undo} aria-label="Undo" on:click={() => dispatch("undo")} />
Copy link
Member

Choose a reason for hiding this comment

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

Follwing on from the above, when that is done we will need to change this to label=....

<IconButton Icon={Brush} on:click={() => (show_size = !show_size)} />
<IconButton
Icon={Brush}
aria-label="Use brush"
Copy link
Member

Choose a reason for hiding this comment

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

label

ui/packages/image/src/SketchSettings.svelte Show resolved Hide resolved
<IconButton Icon={Color} on:click={() => (show_col = !show_col)} />
<IconButton
Icon={Color}
aria-label="Select brush color"
Copy link
Member

Choose a reason for hiding this comment

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

label

ui/packages/image/src/SketchSettings.svelte Show resolved Hide resolved
<IconButton Icon={Edit} on:click={() => dispatch("edit")} />
<IconButton
Icon={Edit}
aria-label="Edit"
Copy link
Member

Choose a reason for hiding this comment

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

label

{/if}

<IconButton
Icon={Clear}
aria-label="Clear"
Copy link
Member

Choose a reason for hiding this comment

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

label

@emilyuhde
Copy link
Contributor Author

emilyuhde commented Dec 13, 2022

Hi @emilyuhde. Thanks for this!

Just left some comments around the use of $$restProps. When that is adjusted we should be good to go.

This PR will also need to add an item to the CHANGELOG.md.

Under the Upcoming Release heading you need to add something like the following

## Bug Fixes

* Add aria-labels to button icons, improving accessibility by [@emilyuhde](https://github.com/emilyuhde) in [in PR2791](https://github.com/gradio-app/gradio/pull/2791)

Don't worry too much about the conflicts. When this PR is ready, I can resolve those.

No problem @pngwn!

  • I can change the $$restProps to being more explicit, no problem. I wasn't sure if you'd have a preference on this so I went with what I'd normally do for a React component in a library to give as much flexibility as possible.

  • I do have a Changelog line in there; it's probably hard to notice because of the giant diff.

Screen Shot 2022-12-13 at 12 42 55 PM

  • I just sync-ed my fork, I see the conflict and can resolve it

Also, do I need to do anything to get translations hooked up so these strings aren't hard coded?

@emilyuhde emilyuhde requested a review from pngwn December 13, 2022 18:15
@pngwn
Copy link
Member

pngwn commented Dec 14, 2022

I don't understand why the changelog check is failing. @freddyaboulton Do you have any insight here?

@abidlabs
Copy link
Member

It's because the PR number in the changelog is #2777, which corresponds to the issue, whereas it should correspond to the PR itself. If we change that to #2791, it should pass.

Thanks for the PR @emilyuhde!

@emilyuhde
Copy link
Contributor Author

It's because the PR number in the changelog is #2777, which corresponds to the issue, whereas it should correspond to the PR itself. If we change that to #2791, it should pass.

Thanks for the PR @emilyuhde!

You're welcome. Got it, I'll fix that right now.

Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for this @emilyuhde !

@pngwn
Copy link
Member

pngwn commented Dec 14, 2022

I should not have done that.

CHANGELOG.md Outdated Show resolved Hide resolved
@pngwn
Copy link
Member

pngwn commented Dec 14, 2022

i think it is okay now.

@emilyuhde
Copy link
Contributor Author

I'm sure this got lost in the mess, but do I need to do anything so these strings can be translated instead of hard coded in as English? @pngwn

@pngwn
Copy link
Member

pngwn commented Dec 14, 2022

Sorry I did mean to follow that up, my bad.

@pngwn
Copy link
Member

pngwn commented Dec 14, 2022

I just double checked, we don't really have a good mechanism for passing translations that far down (without it getting messy) nor do we have translations for those labels either. i18n is one of thing we are planning to overhaul next year, so i think it is okay to merge this in and deal with i18n a little later so we have some time to figure out a better design (than what we have now).

@emilyuhde
Copy link
Contributor Author

Ok that sounds good then, just wanted to check before this was merged in!

@pngwn
Copy link
Member

pngwn commented Dec 14, 2022

Thanks again @emilyuhde!

@pngwn pngwn merged commit ade918d into gradio-app:main Dec 14, 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.

Add aria-label to icon buttons
3 participants