-
Notifications
You must be signed in to change notification settings - Fork 11
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(AdvancedDataCard): support for href/to #859
Conversation
Size stats
|
Deploy preview for mistica-web ready! ✅ Preview Built with commit 08777c2. |
Accessibility report ℹ️ You can run this locally by executing |
Screenshot tests report ✔️ All passing |
src/community/advanced-data-card.tsx
Outdated
@@ -289,6 +281,7 @@ export const AdvancedDataCard = React.forwardRef<HTMLDivElement, AdvancedDataCar | |||
maybe | |||
className={classNames(styles.touchableContainer, {[styles.hoverEffect]: !!onPress})} | |||
aria-label={ariaLabel} | |||
role="link" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why role link?
Touchable
renders as html <button>
(role button) when used with onPress
prop and as html <a>
(role link) when used with href
/to
prop . If you want a link, I think the best approach is adding href
/to
support to AdvancedDataCard
as we have in other cards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Abel,
This PR is still under review of accessibility team, we upload here to generate the preview link for them.
Most grateful for your contribution at this time :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the role='link' was to be able to adjust the accessibility semantics without changing any properties, but I implemented the href according to your suggestion
playroom/snippets.tsx
Outdated
@@ -2343,7 +2343,7 @@ const advancedDataCardSnippets = [ | |||
} | |||
footerText="footer text" | |||
onClose={() => window.alert("close")} | |||
onPress={() => window.alert("click")} | |||
href="asdf" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
href="asdf" | |
href="https://google.com" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not expected, is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was not expected, but the slightly larger size is due to the touchable being moved into the internal component that encompasses pretitle, title etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, my focus of the review is not this kind of technical details but I would like to understand why the replacement of onPress by href and does not support both properties (like the rest of the cards)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for changing from onPress to href is due to the screen reader, with onPress it would be read as a button, while href as a link which would be more suitable for accessibility
src/community/advanced-data-card.tsx
Outdated
href={href} | ||
aria-label={ariaLabel} | ||
> | ||
<div /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this empty div? and why are you creating an empty link (Touchable
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty div is because the touchable must have a child, and the reason the touchable is there is so the touchable does not interfere with the screen reader's reading order.
Touchable is a link, as it must be read as such in the screen reader, where it receives the link from the href prop previously as onPress.
@@ -38,9 +38,18 @@ export const actions = style([ | |||
}, | |||
]); | |||
|
|||
export const touchableAccessibility = style({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use a more semantic name
@@ -95,6 +103,8 @@ export const cardContentStyle = style([ | |||
}, | |||
]); | |||
|
|||
export const zindex = style({zIndex: -20}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why -20?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The negative z-index is so that images in slots (like SimpleBlock) don't overlap the Touchable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this number doesn't make sense to me. I'm sure you can reorder the elements, use different stacking contexts or using a more sensible zIndex value than -20
src/community/advanced-data-card.tsx
Outdated
onPress?: () => void; | ||
href?: string | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a breaking change, we should avoid breaking changes, otherwise we'd need to generate a major version. Also why don't you support href
/onPress
/to
as we do with other cards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from onPress to href is so that on the screen reader it can be read as a link instead of a button.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @atabel,
Is something pending on our side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't make a major version just for this breaking change, we need to support onPress
+ href
, and we also can include to
to have parity with the rest of the cards. But we need to keep onPress because in master is already existing and there are teams using this prop.
@EduardoLafuente @BrunoGuimaraes103
@@ -95,6 +103,8 @@ export const cardContentStyle = style([ | |||
}, | |||
]); | |||
|
|||
export const zindex = style({zIndex: -20}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this number doesn't make sense to me. I'm sure you can reorder the elements, use different stacking contexts or using a more sensible zIndex value than -20
src/community/advanced-data-card.tsx
Outdated
@@ -261,7 +290,7 @@ export const AdvancedDataCard = React.forwardRef<HTMLDivElement, AdvancedDataCar | |||
}, | |||
ref | |||
) => { | |||
const isTouchable = !!onPress; | |||
const isTouchable = !!href || !!onPress; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about to
?
src/community/advanced-data-card.tsx
Outdated
tabIndex={0} | ||
maybe | ||
className={classNames(styles.touchableArea)} | ||
as="a" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed, Touchable renders an <a>
when used with href
or to
src/community/advanced-data-card.tsx
Outdated
onPress?: () => void; | ||
href?: string | undefined; | ||
to?: undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to
/href
/onPress
shouldn't be allowed at the same time. You can use ExclusifyUnion
to help you with this.
Please, review how we do the same in other mistica cards: https://github.com/Telefonica/mistica-web/blob/master/src/card.tsx#L416-L425
src/community/advanced-data-card.tsx
Outdated
onPress?: () => void; | ||
href?: string | undefined; | ||
to?: undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove to/href/onPress from common props, you are already defining them in the ExclusifyUnion
src/community/advanced-data-card.tsx
Outdated
@@ -43,9 +46,13 @@ type CardContentProps = { | |||
subtitleLinesMax?: number; | |||
description?: string; | |||
descriptionLinesMax?: number; | |||
href?: string; | |||
to?: undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to
shouldn't be undefined here.
You should use ExclusifyUnion here too, like you do in AdvancedDataCardProps
src/community/advanced-data-card.tsx
Outdated
{href ? ( | ||
<Touchable | ||
tabIndex={0} | ||
maybe | ||
className={classNames(styles.touchableArea)} | ||
href={href} | ||
to={to} | ||
aria-label={ariaLabel} | ||
> | ||
<div /> | ||
</Touchable> | ||
) : ( | ||
<Touchable | ||
tabIndex={0} | ||
maybe | ||
className={classNames(styles.touchableArea)} | ||
onPress={onPress} | ||
to={to} | ||
aria-label={ariaLabel} | ||
> | ||
{title} | ||
</Text> | ||
<div /> | ||
</Touchable> | ||
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can simplify this by doing something like this: https://github.com/Telefonica/mistica-web/blob/master/src/card.tsx#L511
🎉 This PR is included in version 14.32.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
PR for Advanced Data Card accessibility testing