-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Insert link accessibility #1575
Conversation
blocks/editable/format-toolbar.js
Outdated
@@ -151,17 +151,19 @@ class FormatToolbar extends Component { | |||
className="editable-format-toolbar__link-modal" | |||
style={ linkStyle } | |||
onSubmit={ this.submitLink }> | |||
<label className="screen-reader-text" htmlFor="editable-format-toolbar__link-input">URL</label> |
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.
This should be { __( 'URL' ) }
so it's translatable
blocks/library/button/index.js
Outdated
@@ -60,15 +60,17 @@ registerBlockType( 'core/button', { | |||
<form | |||
className="editable-format-toolbar__link-modal" | |||
onSubmit={ ( event ) => event.preventDefault() }> | |||
<label className="screen-reader-text" htmlFor="editable-format-toolbar__link-input">URL</label> |
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.
This should be { __( 'URL' ) }
so it's translatable.
Thank you @swissspidy. |
blocks/editable/format-toolbar.js
Outdated
<input | ||
autoFocus | ||
className="editable-format-toolbar__link-input" | ||
id="editable-format-toolbar__link-input" |
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.
Ids should contain a unique uuid. We should consider using the withInstanceId HoC
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.
Thank you for the linked reference. I'll update the PR to contain it.
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.
@youknowriad
I attempted to make use of withinstanceId, but this fails to work.
I imported the component, and loaded it in the render function as a parameter, but I wasn't able to. I'm not sure whether this ID is needed to be passed into the constructor, or somewhere else, but I'm not able to figure out how to do that.
This is where I attempted to do this:
xwp@7aef002
The error I get is:
format-toolbar.js:121 Uncaught TypeError: Cannot read property 'instanceId' of undefined
I also double-checked and the "editable-format-toolbar__link-modal" only shows up once at all time in the DOM. When trying to add a new link the previous link modal is removed from the DOM before adding the new modal, therefore an ID isn't required in this particular case.
I haven't committed the uuid in this PR, so the feature is still fully functional.
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.
@mehigh Instead of export default FormatToolbar;
you'd need to use export default withInstanceId( FormatToolbar );
in order to make it work.
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.
Thank you. I'll give that a try.
Cannot read property 'instanceId' of undefined
Feature/694 instanceId
@swissspidy Even after adding the export default withInstanceId I couldn't pass instanceId as a parameter to the render() function, where I needed to make use of it. Instance ID appearing (it was 10 in that example): Thank you for your reviews. |
@mehigh thanks! Looks good to me, I think the only thing left is that also the input field for the button block needs a unique ID. |
@afercia
The button component doesn't have an export statement, so I'm curious on whether the withInstanceId works within it or not. I'll have to test it and see. |
@mehigh updating the description doesn't trigger a notification ;) And yes, because of the way the button block uses the link inline toolbar, I'm not sure there's a way to use |
I was curios that your comment was spot on to the addition I made to the description. Wanted to check whether that triggered your response :). I'll await for input from aduth / youknowriad and see whether this can be brought home and merged in. |
@aduth / @youknowriad |
A block's diff --git a/blocks/library/button/index.js b/blocks/library/button/index.js
index d49c0344..0d4f9b0e 100644
--- a/blocks/library/button/index.js
+++ b/blocks/library/button/index.js
@@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __ } from 'i18n';
-import { IconButton } from 'components';
+import { IconButton, withInstanceId } from 'components';
/**
* Internal dependencies
@@ -36,9 +36,10 @@ registerBlockType( 'core/button', {
}
},
- edit( { attributes, setAttributes, focus, setFocus, className } ) {
+ edit: withInstanceId( ( { attributes, setAttributes, focus, setFocus, className, instanceId } ) => {
const { text, url, title, align } = attributes;
const updateAlignment = ( nextAlign ) => setAttributes( { align: nextAlign } );
+ const inputId = `editable-format-toolbar__link-input-${ instanceId }`;
return [
focus && (
@@ -61,10 +62,15 @@ registerBlockType( 'core/button', {
<form
className="editable-format-toolbar__link-modal"
onSubmit={ ( event ) => event.preventDefault() }>
- <label className="screen-reader-text" htmlFor="editable-format-toolbar__link-input">{ __( 'URL' ) }</label>
+ <label
+ className="screen-reader-text"
+ htmlFor={ inputId }
+ >
+ { __( 'URL' ) }
+ </label>
<input
className="editable-format-toolbar__link-input"
- id="editable-format-toolbar__link-input"
+ id={ inputId }
type="url"
required
value={ url }
@@ -76,7 +82,7 @@ registerBlockType( 'core/button', {
}
</span>,
];
- },
+ } ),
save( { attributes } ) {
const { url, text, title, align = 'none' } = attributes; Alternatively, we can split this out into a separate component. Like @afercia mentions, we should probably create a common component for applying links to avoid managing separate implementations between the formatting toolbar and button link. I think the patch above is a reasonable interim solution for 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.
Thank you, @aduth for the review and for pointing it out how the ID property can be passed through the edit component. I'll amend the PR tomorrow or on Monday. |
@aduth changes have been applied, while adjusting the ID to "editable-format-toolbar__button-link-input-XX" from "editable-format-toolbar__link-input-" in order to avoid a potential clash with the toolbar link form input, as they share different set of IDs. |
Description
Fixes #694 by improving the screen reader accessibility of the element.
My updates apply to the add link and edit link pop-out elements, handling the following aspects:
How Has This Been Tested?
I used the browser's inspector (screenshots reflect that) to confirm the presence of the a11y attributes and screen-reader-text elements on both the add link and edit link forms.
The updates done in blocks/editable/format-toolbar.js were visible in the add link / edit existing link workflow in the text block, just like the screenshots show.
I wasn't able to figure out where is the "blocks/library/button/index.js" actually used. It has in the edit function a form with a class of editable-format-toolbar__link-modal, just like the one generated with the insert/edit URL.
Locally only I tried adding an extra class on the form.editable-format-toolbar__link-modal and trying to hunt it in the browser, but I wasn't able to stumble upon it myself. That's why the changes done on that file are minimal (added the button aria-label and added a and added an ID to the URL input element itself, without making use of withInstanceId - because there is no export default I could add the withInstanceId call around).
Screenshots:
Add link form:
Edit link form:
Types of changes
New feature (non-breaking change which adds functionality).
Checklist: