-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
2777 Add restProps to IconButton … #2791
Conversation
…to the button element where it's used in other UI components
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! |
There was a problem hiding this 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} |
There was a problem hiding this comment.
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")} /> |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label
<IconButton Icon={Color} on:click={() => (show_col = !show_col)} /> | ||
<IconButton | ||
Icon={Color} | ||
aria-label="Select brush color" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label
<IconButton Icon={Edit} on:click={() => dispatch("edit")} /> | ||
<IconButton | ||
Icon={Edit} | ||
aria-label="Edit" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label
No problem @pngwn!
Also, do I need to do anything to get translations hooked up so these strings aren't hard coded? |
I don't understand why the changelog check is failing. @freddyaboulton Do you have any insight here? |
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. |
There was a problem hiding this 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 !
I should not have done that. |
i think it is okay now. |
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 |
Sorry I did mean to follow that up, my bad. |
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. |
Ok that sounds good then, just wanted to check before this was merged in! |
Thanks again @emilyuhde! |
… 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:
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.