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

[accordion] New Accordion components and hooks #577

Open
wants to merge 48 commits into
base: master
Choose a base branch
from

Conversation

mj12albert
Copy link
Member

@mj12albert mj12albert commented Sep 3, 2024

Closes #25
Closes #627
Closes #702

Builds on top of:

Preview

👉 https://deploy-preview-577--base-ui.netlify.app/components/react-accordion

Summary

Accordion is built using Collapsible, some changes were made to Collapsible while working on this:

  • useCollapsibleTrigger (and Collapsible/AccordionTrigger) now uses useButton
  • Collapsible.Content is now renamed to Collapsible.Panel
  • perf improvements: reduced the use of window.getComputedStyle to an absolute minimum, merged the internal states into one
  • style hooks follows the latest convention: [data-open] on the panel, and [data-panel-open] on the trigger

Accordion features

  • orientation: 'vertical' | 'horizontal': sets a data attr and navigates focus between triggers with ArrowRight/Left instead of ArrowDown/Up
  • Collapsible.Content now exposes the --collapsible-content-width var to support horizontal orientation
  • direction: 'ltr' | 'rtl': sets the dir attr like other components and reverses ArrowRight & ArrowLeft when orientation === 'horizontal'
  • openMultiple: boolean: default true, controls whether multiple sections can be open at the same time, not expected to change during the lifetime of the component
  • disabled can be set on the Root, Section, or Trigger
  • hidden="until-found" can be set on the Root or a Panel

Extra demos

@mj12albert mj12albert added new feature New feature or request component: accordion This is the name of the generic UI component, not the React module! labels Sep 3, 2024
@mui-bot
Copy link

mui-bot commented Sep 3, 2024

Netlify deploy preview

https://deploy-preview-577--base-ui.netlify.app/

Generated by 🚫 dangerJS against e1134df

@mj12albert mj12albert force-pushed the feat/accordion branch 4 times, most recently from 36e29e3 to 881476c Compare September 3, 2024 15:02
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 4, 2024
@mj12albert mj12albert force-pushed the feat/accordion branch 2 times, most recently from 84b0482 to e16cad0 Compare September 4, 2024 05:33
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 4, 2024
@mj12albert mj12albert force-pushed the feat/accordion branch 7 times, most recently from bb181bf to c735efb Compare September 4, 2024 07:49
@mj12albert mj12albert marked this pull request as ready for review September 4, 2024 07:50
@mj12albert mj12albert force-pushed the feat/accordion branch 3 times, most recently from b5f818e to 6969cd2 Compare September 5, 2024 05:11
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 5, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 5, 2024
@mj12albert mj12albert force-pushed the feat/accordion branch 2 times, most recently from 18f8e1c to a53c395 Compare October 16, 2024 14:37
@mj12albert mj12albert marked this pull request as ready for review October 16, 2024 15:55
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 17, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 17, 2024
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 18, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 21, 2024
Comment on lines 87 to 95
customStyleHookMapping: {
disabled: (isDisabled) => {
if (isDisabled) {
return { 'data-disabled': '' };
}
return null;
},
value: () => null,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be placed outside the component. I don't think data-disabled needs a custom style hook as this should work by default?

Copy link
Member Author

Choose a reason for hiding this comment

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

@atomiks Moved - by default disabled becomes data-disabled="true" instead of just data-disabled which seems a bit better, maybe the getStyleHookProps util could be updated to handle this universally?

Copy link
Member

Choose a reason for hiding this comment

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

I'm ok with just data-disabled and whatever we choose, we should apply to all components. So getStyleHookProps should handle it.

Copy link
Member Author

Choose a reason for hiding this comment

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

2c8327e
Since we already don't render any data attr when the value is false, I think we could change all data-attr='true' to just data-attr (e.g. data-readonly, data-required...)

docs/data/components/accordion/accordion.mdx Outdated Show resolved Hide resolved
When uncontrolled, use the `defaultValue` prop to set the initial state of the accordion:

```tsx
<Accordion.Root defaultValue={[0]}>
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if openPanels wouldn't make more sense than value (and now that I think of it, I'd rename Tabs's value as well).

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree the API for Tabs and Accordion should be as similar as possible, wonder what @vladmoroz and @colmtuite think?
The API would be openPanels/defaultOpenPanels? and onOpenPanelChange?

Copy link
Contributor

Choose a reason for hiding this comment

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

@michaldudak what would value become on the item itself? E.g. here <Accordion.Item value="1">

Copy link
Member

Choose a reason for hiding this comment

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

value on items still makes sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: accordion This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
7 participants