Skip to content

feat(s2): update accordion api to allow sibling elements in disclosure header #7179

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

Merged
merged 12 commits into from
Oct 17, 2024

Conversation

yihuiliao
Copy link
Member

Closes

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@rspbot
Copy link

rspbot commented Oct 11, 2024

reidbarber
reidbarber previously approved these changes Oct 11, 2024
Copy link
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

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

API and styles look good.

style={UNSAFE_style}
className={(UNSAFE_className ?? '') + style({display: 'flex', alignItems: 'center', gap: 4})}
ref={domRef}>
{children}
Copy link
Member

@reidbarber reidbarber Oct 11, 2024

Choose a reason for hiding this comment

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

An option for shorthand: if typeof children === 'string', we could automatically wrap children in a DisclosureTrigger, which would let you use our existing API as well.

No need to implement this now, we could discuss it later

@yihuiliao
Copy link
Member Author

I'll update the chromatic stories as well once we settle on the API that we like

Copy link
Member

@ktabors ktabors left a comment

Choose a reason for hiding this comment

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

This is great! Just a few observations.

Density compact seems to have a focus ring issue.
image

@@ -34,15 +36,19 @@ export const Example: Story = {
<Accordion {...args}>
<Disclosure id="files">
<DisclosureHeader>
Files
<DisclosureTrigger>
Copy link
Member

Choose a reason for hiding this comment

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

This pattern is opposite to our other triggers
<DialogTrigger> is the outermost, whereas here, DisclosureTrigger is the innermost

Copy link
Member

Choose a reason for hiding this comment

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

That's because the header can contain elements that are not part of the trigger (eg adjacent buttons).

Copy link
Member

Choose a reason for hiding this comment

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

I understand that, but it also doesn't include the element that it opens like our other triggers
See my other concerns in my next comment down about level

};

// maps to one size smaller in the compact density to ensure there is space between the top and bottom of the action button and container
// @ts-ignore
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'll take a look at this later, just wanted to get the lint working for testing

Copy link
Member

Choose a reason for hiding this comment

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

what was the error?

@rspbot
Copy link

rspbot commented Oct 14, 2024

@devongovett
Copy link
Member

My only question is whether we want to have a shortcut so you don't need to write <DisclosureHeader><DisclosureTitle>Title</DisclosureTitle></DisclosureHeader> in the common case where there are no sibling buttons. We could potentially have just <DisclosureTitle> and automatically wrap in a header if it isn't already in one, similar to what we do with <Modal> and <ModalOverlay>. There may be other options as well. Anyone else have input?

@snowystinger
Copy link
Member

Does it make more sense to have DisclosureTitle do the shortcut wrapping? It feels opposite to button and DisclosureHeader should wrap a string child in the DisclosureTitle automatically

@devongovett
Copy link
Member

It feels opposite to button and DisclosureHeader should wrap a string child in the DisclosureTitle automatically

But then as soon as you put a <span> or <FormatMessage> or something it wouldn't work right?

@snowystinger
Copy link
Member

It feels opposite to button and DisclosureHeader should wrap a string child in the DisclosureTitle automatically

But then as soon as you put a <span> or <FormatMessage> or something it wouldn't work right?

This is true. I guess I'm ok with it. I don't have a better idea.

};

// maps to one size smaller in the compact density to ensure there is space between the top and bottom of the action button and container
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

what was the error?

@rspbot
Copy link

rspbot commented Oct 14, 2024

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

UPDATE seems to have been a cache issue, I can't reproduce in incognito

Seeing an error when I try to visit the storybook build https://reactspectrum.blob.core.windows.net/reactspectrum/844be69102b36467a58c5be2e1aaee9e90d50c48/storybook/index.html?path=/story/accordion--default&providerSwitcher-express=false

Not seeing the error on Main, but this only have changes for s2... so I'm not sure what has changed.

snowystinger
snowystinger previously approved these changes Oct 15, 2024
Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

are we doing the auto wrapping in a followup?

@yihuiliao
Copy link
Member Author

are we doing the auto wrapping in a followup?

i'll just do it in this pr. i'd like to get the api figured out so that i can update the chromatic stories too

@rspbot
Copy link

rspbot commented Oct 15, 2024

Copy link
Member

@ktabors ktabors left a comment

Choose a reason for hiding this comment

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

Out of scope. Shouldn't there be an example with an expanded disclosure?

@yihuiliao yihuiliao changed the title Update S2 Accordion API feat: update accordion api to allow sibling elements in disclosure header Oct 15, 2024
@yihuiliao yihuiliao changed the title feat: update accordion api to allow sibling elements in disclosure header feat(s2): update accordion api to allow sibling elements in disclosure header Oct 15, 2024
@rspbot
Copy link

rspbot commented Oct 15, 2024

@rspbot
Copy link

rspbot commented Oct 16, 2024

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

looks like a style got lost somewhere?
https://www.chromatic.com/build?appId=5f0dd5ad2b5fc10022a2e320&number=807

actually, looks like I can't interact with/open the disclosure anymore for some of these

@yihuiliao
Copy link
Member Author

yihuiliao commented Oct 16, 2024

looks like a style got lost somewhere? https://www.chromatic.com/build?appId=5f0dd5ad2b5fc10022a2e320&number=807

ah good catch. i think that's because i forgot to update the chromatic stories to use DisclosureTitle.

actually, looks like I can't interact with/open the disclosure anymore for some of these

which one's specifically can you not interact with/open and which browser? im not able to reproduce

@rspbot
Copy link

rspbot commented Oct 16, 2024

@rspbot
Copy link

rspbot commented Oct 16, 2024

## API Changes

@react-spectrum/s2

/@react-spectrum/s2:DisclosureHeader

 DisclosureHeader {
   UNSAFE_className?: string
   UNSAFE_style?: CSSProperties
   children: React.ReactNode
   id?: string
-  level?: number = 3
 }

/@react-spectrum/s2:DisclosureTitle

+DisclosureTitle {
+  UNSAFE_className?: string
+  UNSAFE_style?: CSSProperties
+  children: React.ReactNode
+  id?: string
+  level?: number = 3
+}

@snowystinger
Copy link
Member

This is the chromatic story where i couldn't open it https://5f0dd5ad2b5fc10022a2e320-ykjpggsppc.chromatic.com/?path=/story/s2-chromatic-disclosure--example which is explained by not using the right elements. It's fixed now with your updates.

@yihuiliao yihuiliao added this pull request to the merge queue Oct 17, 2024
Merged via the queue into main with commit b958085 Oct 17, 2024
32 checks passed
@yihuiliao yihuiliao deleted the update-s2-accordion-api branch October 17, 2024 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants