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(Touchable, Buttons): Improve touchable and buttons accessibility #1070

Merged
merged 8 commits into from
Apr 8, 2024

Conversation

pladaria
Copy link
Member

@pladaria pladaria commented Apr 4, 2024

https://jira.tid.es/browse/WEB-1794

This PR adds the onNavigate and role props to:

  • Touchable
  • ButtonPrimary, ButtonSecondary, etc
  • ButtonLink
  • TextLink

There are other touchable-like components like IconButton, Row, Card, Chip... We can add these features when required but I think the scope of this PR is Ok for now

Copy link

github-actions bot commented Apr 4, 2024

Size stats

master this branch diff
Total JS 10.6 MB 10.6 MB +411 B
JS without icons 1.9 MB 1.9 MB +411 B
Lib overhead 51.2 kB 51.2 kB 0 B
Lib overhead (gzip) 13.8 kB 13.8 kB 0 B

Copy link

github-actions bot commented Apr 4, 2024

Accessibility report
✔️ No issues found

ℹ️ You can run this locally by executing yarn audit-accessibility.

@@ -0,0 +1,9 @@
export const redirect = (url: string, external = false, loadOnTop = false): void => {
Copy link
Member Author

@pladaria pladaria Apr 4, 2024

Choose a reason for hiding this comment

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

moved from touchable to facilitate testing

Copy link

github-actions bot commented Apr 4, 2024

Deploy preview for mistica-web ready!

✅ Preview
https://mistica-bsdmnaqux-tuentisre.vercel.app

Built with commit 27a935f.
This pull request is being automatically deployed with vercel-action

@@ -377,7 +384,7 @@ const Button = React.forwardRef<TouchableElement, ButtonProps & {type: ButtonTyp
EndIcon: props.EndIcon,
}),
disabled: props.disabled || showSpinner || isFormSending,
role: 'button',
role: props.role,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we default to button in case role was not provided?

Copy link
Member Author

Choose a reason for hiding this comment

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

the default is provided by the dom element (button for <button> and link for <a>)

maybe: true;
to?: string | Location;
fullPageOnWebView?: boolean;
replace?: boolean;
href?: undefined;
onPress?: undefined;
/** with "to", onNavigate will be executed in parallel to the navigation */
Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I can see, it's not in parallel, right? You wait for the promise to be resolved, and after that you navigate

Copy link
Member Author

Choose a reason for hiding this comment

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

what you comment is true in the "href", not for the "to".

The "to" prop will use a <Link> element which produces a client side navigation, so it is ok to perform the onNavigate actions in parallel (this was already happening in current implementation)

Copy link
Collaborator

@atabel atabel left a comment

Choose a reason for hiding this comment

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

Please, create a ticket to add onNavigate prop to cards, rows, etc

playroom/components/index.tsx Outdated Show resolved Hide resolved
@@ -44,18 +64,13 @@ test('<a> is rendered when using "to" prop', () => {
</ThemeContextProvider>
);

const anchor = screen.getByRole('button', {name: 'test'});
const anchor = screen.getByRole('link', {name: 'test'});
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this is an expected change, but it will probably break many tests in webapp

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we could have a TouchableProps<T> generic type to reuse all the onPress/to/href + friend props in any touchable component (Buttons, IconButton, Cards, Rows, etc).

I've created a ticket: https://jira.tid.es/browse/WEB-1817

@pladaria
Copy link
Member Author

pladaria commented Apr 8, 2024

Please, create a ticket to add onNavigate prop to cards, rows, etc

https://jira.tid.es/browse/WEB-1818

@atabel atabel added this pull request to the merge queue Apr 8, 2024
Merged via the queue into master with commit 8d93c71 Apr 8, 2024
11 checks passed
@atabel atabel deleted the pladaria/WEB-1794_improve-buttons-a11y branch April 8, 2024 14:38
tuentisre pushed a commit that referenced this pull request Apr 8, 2024
# [15.1.0](v15.0.0...v15.1.0) (2024-04-08)

### Bug Fixes

* **IconButton:** prevent interactive area from affecting button layout ([#1069](#1069)) ([f377aac](f377aac))

### Features

* **Accordion,Callout,Cards,EmptyState,Header,Hero,Row,NavigationBar:** added titleAs prop to allow configuring heading level ([#1067](#1067)) ([814c297](814c297))
* **RowList, BoxedRowList, Inline:** support list a11y role ([#1068](#1068)) ([7e2fe37](7e2fe37)), closes [/github.com/Telefonica/mistica-web/blob/master/src/stack.tsx#L64](https:/Telefonica/mistica-web/blob/master/src/stack.tsx/issues/L64)
* **skin:** o2 new brand ([#968](#968)) ([56e3945](56e3945))
* **Switch:** add minimum interactive area in touchable devices ([#1063](#1063)) ([fb202e7](fb202e7))
* **Touchable, Buttons:** Improve touchable and buttons accessibility ([#1070](#1070)) ([8d93c71](8d93c71))
@tuentisre
Copy link
Collaborator

🎉 This PR is included in version 15.1.0 🎉

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
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants