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

feat: add attributes to input and wrapper component #2570

Merged

Conversation

httpsmenahassan
Copy link
Contributor

@httpsmenahassan httpsmenahassan commented Aug 22, 2023

Description

Resolves #2438.

  • Create IDs for items in dropdown
  • Add aria-activedescendant attribute to input to identify to assistive technologies which item in the dropdown is being focused
  • Add aria-live=”assertive” to wrapper component to allow screen readers to read out the number of options in the dropdown

Deploy Preview

https://deploy-preview-2570--paragon-openedx.netlify.app/components/form/form-autosuggest/

Merge Checklist

  • Is there adequate test coverage for your changes?
  • Consider whether this change needs to reviewed/QA'ed for accessibility (a11y). If so, please add wittjeff and adamstankiewicz as reviewers on this PR.

Post-merge Checklist

  • Verify your changes were released to NPM at the expected version.
  • If you'd like, share your contribution in #show-and-tell.
  • 🎉 🙌 Celebrate! Thanks for your contribution.

@netlify
Copy link

netlify bot commented Aug 22, 2023

Deploy Preview for paragon-openedx ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2d57bc9
🔍 Latest deploy log https://app.netlify.com/sites/paragon-openedx/deploys/650b481ac4c2b800088e8fc9
😎 Deploy Preview https://deploy-preview-2570--paragon-openedx.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@httpsmenahassan httpsmenahassan force-pushed the attributesForm.Autosuggest branch from 3d11100 to 236afbc Compare August 23, 2023 00:40
@codecov
Copy link

codecov bot commented Aug 23, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.43% 🎉

Comparison is base (0291845) 91.81% compared to head (2d57bc9) 92.25%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2570      +/-   ##
==========================================
+ Coverage   91.81%   92.25%   +0.43%     
==========================================
  Files         235      235              
  Lines        4217     4222       +5     
  Branches     1020     1020              
==========================================
+ Hits         3872     3895      +23     
+ Misses        341      323      -18     
  Partials        4        4              
Files Changed Coverage Δ
src/Form/FormAutosuggest.jsx 93.87% <100.00%> (+0.32%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

// eslint-disable-next-line no-shadow
const { children, onClick, ...rest } = child.props;
// Generate a unique ID for each menu item
const menuItemId = `pgn__form-autosuggest__menuItem-${index}`;
Copy link
Member

@adamstankiewicz adamstankiewicz Aug 23, 2023

Choose a reason for hiding this comment

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

Two questions here:

  1. Duplicate IDs are possible here (e.g., if there are multiple FormAutosuggest components rendered at the same time in the UI with the same number of children. There might be an opportunity to be use name to differentiate between multiple FormAutosuggest components? That said, it doesn't appear to be a required field as is.
  2. Is there a concern if/when the children change order between re-renders? In theory, the index would be different between re-renders on each item.

Copy link
Contributor

Choose a reason for hiding this comment

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

it seems on http://react-autosuggest.js.org/ the ids will update as the items in the dropdown change

image

image

Copy link
Member

Choose a reason for hiding this comment

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

As long as the id changes in all the appropriate places at the same time (which I'm assuming is the same; that is, it doesn't update the ID in one place and leave it unchanged somewhere else), I imagine the re-rendering/re-ordering of React.Children wouldn't be an issue. Just worth a sanity check :)

@brian-smith-tcril
Copy link
Contributor

@adamstankiewicz just to verify/document decisions from Paragon WG today:

  • make name a required prop for autosuggest
  • ensure we generate unique ids (something like autoSuggestName-uuid) to set aria-activedescendant

@adamstankiewicz
Copy link
Member

@brian-smith-tcril @httpsmenahassan

make name a required prop for autosuggest

I'd like to better understand how and why name is used today. It looks like it is only passed to a feedback-for attribute, but on a quick search, I'm struggling to find any documentation on if this is a standard attribute related to a11y. I haven't seen feedback-for used on the FormControlFeedback component before...

If we truly need it, then we'll need to consider making it a required prop. Ideally, though, the solution for generating unique IDs wouldn't rely on the prop as if it did, we'd need to make a breaking change to make the name (or otherwise) prop required.

ensure we generate unique ids (something like autoSuggestName-uuid) to set aria-activedescendant

If the ID is guaranteed to be unique based on a uuid, I don't think the name bit above is relevant? FWIW, we generate a UUID for use in React key attributes in some places to ensure uniqueness:

import { v4 as uuidv4 } from 'uuid';

We also use this newId function in Paragon (source) to generate unique IDs in some places.

@brian-smith-tcril
Copy link
Contributor

@adamstankiewicz if we can avoid making name a required prop and instead just do the uuid thing that works perfectly imo

@httpsmenahassan httpsmenahassan force-pushed the attributesForm.Autosuggest branch 2 times, most recently from 9f7ac7e to f557bc6 Compare August 25, 2023 18:06
@httpsmenahassan httpsmenahassan force-pushed the attributesForm.Autosuggest branch from f557bc6 to 4fd71b4 Compare September 20, 2023 01:56
@httpsmenahassan httpsmenahassan changed the title Attributes form.autosuggest fix: disable browser autocomplete and edit dropdown items elements Sep 20, 2023
@httpsmenahassan httpsmenahassan force-pushed the attributesForm.Autosuggest branch 2 times, most recently from 3114298 to e18a794 Compare September 20, 2023 14:40
@httpsmenahassan httpsmenahassan changed the title fix: disable browser autocomplete and edit dropdown items elements feat: add attributes to input and wrapper component Sep 20, 2023
@httpsmenahassan httpsmenahassan force-pushed the attributesForm.Autosuggest branch from e18a794 to 4471d66 Compare September 20, 2023 18:43
Create IDs for items in dropdown. Add aria-activedescendant attribute to input to identify to assistive technologies
which item in the dropdown is being focused. Add aria-live=”assertive” to wrapper component to allow screen readers to
read out the number of options in the dropdown.
@httpsmenahassan httpsmenahassan force-pushed the attributesForm.Autosuggest branch from 4471d66 to 2d57bc9 Compare September 20, 2023 19:29
@httpsmenahassan httpsmenahassan marked this pull request as ready for review September 20, 2023 19:51
Copy link
Contributor

@brian-smith-tcril brian-smith-tcril left a comment

Choose a reason for hiding this comment

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

Awesome! :shipit:

@brian-smith-tcril brian-smith-tcril merged commit acf452b into openedx:master Oct 11, 2023
8 checks passed
@edx-semantic-release
Copy link
Contributor

🎉 This PR is included in version 21.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@edx-semantic-release
Copy link
Contributor

🎉 This PR is included in version 22.0.0-alpha.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Form.Autosuggest Accessibility - Attributes
4 participants