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

Allow editable to accept aria attributes #3106

Merged
merged 6 commits into from
Oct 29, 2017

Conversation

BoardJames
Copy link

Description

Previously the TinyMCE component in Editable could only have the aria-label attribute but it is apparent that an accessible implementation of auto-completion and probably other things will require setting additional aria attributes (see #2896 (comment) ) so I have created this small PR to enable passing through any ARIA attribute in the same way that styles are passed.

How Has This Been Tested?

I manually changed autocomplete to pass through the aria-activedescendant which was set to the current autocomplete value and it updated the property on tinymce as the autocomplete selection changed as expected. Tested on Firefox and Chrome.
With the current headless test framework I can't think of a way to automate testing of this but that could be added at a later date when in-browser automated testing becomes available.

Types of changes

New feature.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows has proper inline documentation.

@BoardJames BoardJames self-assigned this Oct 23, 2017
@codecov
Copy link

codecov bot commented Oct 23, 2017

Codecov Report

Merging #3106 into master will increase coverage by 0.12%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3106      +/-   ##
==========================================
+ Coverage   31.64%   31.76%   +0.12%     
==========================================
  Files         217      218       +1     
  Lines        6282     6302      +20     
  Branches     1116     1116              
==========================================
+ Hits         1988     2002      +14     
- Misses       3610     3616       +6     
  Partials      684      684
Impacted Files Coverage Δ
blocks/editable/tinymce.js 0% <0%> (ø) ⬆️
blocks/editable/aria.js 100% <100%> (ø)
blocks/editable/index.js 11.02% <100%> (+0.32%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aa13720...5764640. Read the comment docs.

@BoardJames BoardJames mentioned this pull request Oct 23, 2017
3 tasks
@aduth
Copy link
Member

aduth commented Oct 23, 2017

See also #2789, which seems to achieve the same goal with a slightly different implementation (supporting other attributes).

@BoardJames
Copy link
Author

Ok, I have looked at it and it might be a good solution for non-aria attributes. I'm not sure that I agree that putting aria attributes on the wrong element is a good idea even if you also put aria-hidden; for example quoting from https://www.w3.org/TR/wai-aria/states_and_properties#aria-owns :

Authors MUST ensure that an element's ID is not specified in more than one other element's aria-owns attribute at any time.

One of these two methods needs to be merged or I can not proceed with making auto-completion accessible.

@ephox-mogran
Copy link
Contributor

@afercia what are your thoughts on this? Can there be multiple DOM nodes with aria-owns pointing to the same id as long as one of those nodes has aria-hidden?

@afercia
Copy link
Contributor

afercia commented Oct 24, 2017

Can there be multiple DOM nodes with aria-owns pointing to the same id as long as one of those nodes has aria-hidden?

Hm good question, I'd stick to the specification and not try to do fancy things.

Authors must ensure that an element's ID is not specified in more than one other element's aria-owns attribute at any time. In other words, an element can have only one explicit owner.

Note that in the W3C specifications, "MUST" has a very mandatory meaning.

Software is designed based on specifications. I don't see why screen readers should be so smart to check aria-hidden before establishing an aria-owns relationship. It may or may not work, but a similar behavior is not described anywhere in the specification and it's just an assumption.

Screen readers are not browsers, they don't read the DOM directly (that would be too expensive), they just get an ID and point to the targeted element. For example, aria-describedby works even if the targeted element is hidden with display: none. I guess the same would happen with aria-owns, getting multiple owners for the same element.

@mcsf
Copy link
Contributor

mcsf commented Oct 25, 2017

@EphoxJames, based on @aduth's feedback in #2789:

† I think ideally someone who renders an Editable could pass these props as the attributes they would expect to be applied, aria-label etc. instead of a custom grouping object, particularly if we're seeking to apply a broad range of attributes.

I've pushed ac1d5f7cd0c8fde2032d816a28a9111a1320dead. Quoting from the commit message, "one benefit we now get for free is that the linter is able to warn the author if they pass an invalid ARIA attribute."

Feel free to argue with the change. :)

const updatedKeys = differenceWith( nextAriaKeys, prevAriaKeys,
( nextKey, prevKey ) =>
nextKey === prevKey &&
nextProps[ nextKey ] === this.props[ prevKey ] );
Copy link
Author

@BoardJames BoardJames Oct 26, 2017

Choose a reason for hiding this comment

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

The changes seem sensible in general.
My only query is why did you calculate the updated keys using an O(n^2) difference algorithm instead of the O(n) filter that I used originally?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wanted to see what this method could look like if we stuck to a single collection interface (difference/differenceWith) and whether it made it any clearer, but you're quite right: it's wasteful and doesn't do much for the reader. Amended and pushed.

With this change, Editable expects ARIA attributes to be provided as
individual props: `<Editable aria-label="foo" />`. This replaces the
approach whereby a single `aria` object prop would be passed.

This allows Editable's interface to be kept similar to any native
element's interface. One benefit we now get for free is that the linter
is able to warn the author if they pass an invalid ARIA attribute:

    aria-foo: This attribute is an invalid ARIA attribute.
    (jsx-a11y/aria-props) [eslint]
@mcsf mcsf force-pushed the add/aria-attributes-on-editable branch from ac1d5f7 to 700f2a1 Compare October 26, 2017 09:02
@mcsf
Copy link
Contributor

mcsf commented Oct 26, 2017

The hand-rolled prop diffing deserves some tests.

@BoardJames
Copy link
Author

Good idea - I will move the prop diffing into aria.js and add some tests.

@BoardJames
Copy link
Author

Ok, tests added. Do you think it is good to merge?

@mcsf
Copy link
Contributor

mcsf commented Oct 28, 2017

Ok, tests added. Do you think it is good to merge?

Looks great!

@BoardJames BoardJames merged commit 1b2c770 into master Oct 29, 2017
@BoardJames BoardJames deleted the add/aria-attributes-on-editable branch October 29, 2017 23:28
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.

6 participants