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

Insert link accessibility #1575

Closed
wants to merge 13 commits into from
Closed

Insert link accessibility #1575

wants to merge 13 commits into from

Conversation

mehigh
Copy link
Contributor

@mehigh mehigh commented Jun 29, 2017

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:

  • The buttons (Apply, Edit, Remove) now have the aria-label attribute added in for accessibility purposes. There is no visual change for them.
  • The URL input now has an ID that makes use of the withInstanceId feature from components
  • The URL input now has a screen-reader-text label which uses the ID on the for attribute to improve the screen reader accessibility of the element. This label is not visible.

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:
Add link

Edit link form:
Edit link

Types of changes

New feature (non-breaking change which adds functionality).

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.

@mehigh mehigh changed the title Insert link accessibility #694 Insert link accessibility Jun 29, 2017
@@ -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>
Copy link
Member

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

@@ -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>
Copy link
Member

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.

@mehigh
Copy link
Contributor Author

mehigh commented Jun 29, 2017

Thank you @swissspidy.
I've handled your feedback.

@ellatrix ellatrix added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Jun 29, 2017
<input
autoFocus
className="editable-format-toolbar__link-input"
id="editable-format-toolbar__link-input"
Copy link
Contributor

@youknowriad youknowriad Jun 29, 2017

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@mehigh
Copy link
Contributor Author

mehigh commented Jul 1, 2017

@swissspidy
I was able to get instanceId working.
I had to look at a few other JS files where this was used to figure out that I need to spread that property into here:
const { formats, focusPosition, enabledControls = DEFAULT_CONTROLS**, instanceId** } = this.props;

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):
Instance ID appearing

Thank you for your reviews.

@afercia
Copy link
Contributor

afercia commented Jul 3, 2017

@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.

screen shot 2017-07-03 at 15 43 28

@mehigh
Copy link
Contributor Author

mehigh commented Jul 3, 2017

@afercia
In believe you read the updated PR description, right? :)

"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."
Thanks for pointing out on where was that URL editing pop-out actually used.

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.

@afercia
Copy link
Contributor

afercia commented Jul 4, 2017

@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 withInstanceId at the moment. On the other hand, the link inline toolbar should probably be a reusable component. Right now, there are two link toolbar that just "look" the same, but they're two different implementations. This is a bit out of the scope of this issue and should probably be addressed in a separate issue. I'd also like to ping @aduth @youknowriad to ask if there are plans to rework the link inline toolbar as a component.

@mehigh
Copy link
Contributor Author

mehigh commented Jul 4, 2017

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.

@mehigh
Copy link
Contributor Author

mehigh commented Jul 12, 2017

@aduth / @youknowriad
Since the 2nd usage of the URL entry doesn't support withInstanceId, I suggest we leave the current implementation as it's accessible and maybe revise in a different ticket if it's decided to merge the two together.
Hope to move this forward.

@aduth
Copy link
Member

aduth commented Jul 13, 2017

A block's edit property is a component, meaning that it can be wrapped with withInstanceId to inject an instanceId prop.

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.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

@mehigh
Copy link
Contributor Author

mehigh commented Jul 13, 2017

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.

@mehigh
Copy link
Contributor Author

mehigh commented Jul 17, 2017

@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.
Thank you for your thorough explanation.

@mehigh mehigh closed this Jul 18, 2017
@mehigh mehigh deleted the feature/694 branch July 18, 2017 08:38
@mehigh mehigh mentioned this pull request Jul 18, 2017
2 tasks
@mehigh
Copy link
Contributor Author

mehigh commented Jul 18, 2017

I tried to rebase this to squash all of the merge master commits, but it yielded too many conflicts.
@aduth everything is available here:
#1933

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants