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(accordion): clickable title #1033

Merged
merged 4 commits into from
May 29, 2024

Conversation

TylerR909
Copy link
Contributor

@TylerR909 TylerR909 commented May 25, 2024

In DesignPackage, we want to be able to select "All these slots" by clicking on a header, like so:

image

This PR adds an optional titleOnClick function that, when provided, slightly alter the behavior of the Accordion:

  1. Clicking the title no longer performs expand/collapse
    • We still want whitespace between the icon and title to be clickable, so it has to fg0 instead of the span's fg1
    • Stop propagation so w don't trigger expand's onClick

bdow
bdow previously requested changes May 25, 2024
if (setExpandedIndex) setExpandedIndex(index);
}}
>
<span css={Css.fg1.tl.$}>{title}</span>
{titleOnClick ? (
<button
Copy link
Contributor

@bdow bdow May 25, 2024

Choose a reason for hiding this comment

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

Suggestion: We should try to avoid nesting interactive elements. Per HTML standards, nesting of interactive elements is not permitted- it's possible, just not advisable.

Content model:
Phrasing content, but there must be no interactive content descendant and no descendant with the tabindex attribute specified.

https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element

Please work with design to determine a way forward where we do not nest interactive elements. We could have buttons side by side, or just make the chevron the click target for expanding/collapsing.

I used to be pretty adamant with the old design crew about avoiding these patterns, and we've been successful so far. I'd like us to keep up with enforcing HTML standards back onto design and share the knowledge.

Fwiw, here's what GPT had to say about it:

Nesting a <button> element inside another <button> element is invalid HTML according to the HTML5 specification. This is because:

  1. Semantic Incorrectness: Buttons are meant to be interactive elements, and nesting one interactive element inside another can create confusion about which element should be interactive.

  2. Accessibility Issues: Screen readers and other assistive technologies may have difficulty interpreting nested buttons, leading to poor user experiences for individuals relying on these tools.

  3. Browser Compatibility: Different browsers may handle nested buttons inconsistently. Some browsers may ignore the nested button, while others may render it in unexpected ways, leading to unpredictable behavior.

  4. Event Handling Confusion: Nesting buttons can create complications in event handling. For instance, click events might not propagate as expected, causing issues in the functionality of the nested buttons.

To maintain valid, accessible, and predictable HTML, it's best to avoid nesting <button> elements inside each other.

@bdow bdow dismissed their stale review May 28, 2024 22:16

Proposed way forward discussed on Slack. I'll be out the next couple days and do not want to block merging.

src/components/Accordion.tsx Outdated Show resolved Hide resolved
<button {...tid.title} disabled={disabled} css={{ ...touchableStyle, ...Css.fg0.$ }} onClick={titleOnClick}>
{title}
</button>
<button {...tid.toggle} disabled={disabled} css={{ ...touchableStyle, ...Css.fg1.jcfe.$ }} onClick={toggle}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think personally I would switch the fg0/1 and have the chevon CTA be smaller, but 🤷 could really see that going either way/defer to you/design.

@TylerR909 TylerR909 merged commit df9a8d6 into main May 29, 2024
6 checks passed
@TylerR909 TylerR909 deleted the sc-51723/designpackage-zoomed-out-multislot-view branch May 29, 2024 19:40
homebound-team-bot pushed a commit that referenced this pull request May 29, 2024
## [2.348.0](v2.347.2...v2.348.0) (2024-05-29)

### Features

* **accordion:** clickable title ([#1033](#1033)) ([df9a8d6](df9a8d6))
@homebound-team-bot
Copy link

🎉 This PR is included in version 2.348.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.

4 participants