Skip to content

Commit

Permalink
Insert link accessibility (#1933)
Browse files Browse the repository at this point in the history
* Insert link accessibility

## 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 <label for> 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](http://files.urldocs.com/share/add-link/add-link.jpg "Add
link form")

Edit link form:
![Edit link](http://files.urldocs.com/share/edit-link/edit-link.jpg
"Edit link form")

## Types of changes
New feature (non-breaking change which adds functionality).

## Checklist:
- [x] My code is tested.
- [x] My code follows the WordPress code style.

* 694 - Fix formatting

* 694 - Removed visually hidden labels, added aria-label attribute on the input

* 694 - Reverted the edit function declaration

* 694 - Dropped accessibility text comment
  • Loading branch information
mehigh authored and aduth committed Jul 18, 2017
1 parent 710fb34 commit 66a865b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions blocks/editable/format-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,14 @@ class FormatToolbar extends Component {
autoFocus
className="editable-format-toolbar__link-input"
type="url"
aria-label={ __( 'URL' ) }
required
value={ this.state.linkValue }
onChange={ this.updateLinkValue }
placeholder={ __( 'Paste URL or type' ) }
/>
<IconButton icon="editor-break" type="submit" />
<IconButton icon="editor-unlink" onClick={ this.dropLink } />
<IconButton icon="editor-break" label={ __( 'Apply' ) } type="submit" />
<IconButton icon="editor-unlink" label={ __( 'Remove link' ) } onClick={ this.dropLink } />
</form>
}

Expand All @@ -174,8 +175,8 @@ class FormatToolbar extends Component {
>
{ this.state.linkValue && decodeURI( this.state.linkValue ) }
</a>
<IconButton icon="edit" onClick={ this.editLink } />
<IconButton icon="editor-unlink" onClick={ this.dropLink } />
<IconButton icon="edit" label={ __( 'Edit' ) } onClick={ this.editLink } />
<IconButton icon="editor-unlink" label={ __( 'Remove link' ) } onClick={ this.dropLink } />
</div>
}
</div>
Expand Down
3 changes: 2 additions & 1 deletion blocks/library/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ registerBlockType( 'core/button', {
<input
className="editable-format-toolbar__link-input"
type="url"
aria-label={ __( 'URL' ) }
required
value={ url }
onChange={ ( event ) => setAttributes( { url: event.target.value } ) }
placeholder={ __( 'Paste URL or type' ) }
/>
<IconButton icon="editor-break" type="submit" />
<IconButton icon="editor-break" label={ __( 'Apply' ) } type="submit" />
</form>
}
</span>,
Expand Down

1 comment on commit 66a865b

@afercia
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice commit message :)

Please sign in to comment.