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

<SegmentedPicker />: Use Radix UI's Tabs component under the hood, and rename to <Tabs /> #1543

Merged
merged 5 commits into from
Jul 26, 2024

Conversation

jessepinho
Copy link
Contributor

@jessepinho jessepinho commented Jul 23, 2024

This PR addresses @VanishMax 's comment about accessibility issues with the <SegmentedPicker /> component. To address the issues, I refactored <SegmentedPicker /> to use Radix UI's fully accessible <Tabs /> component under the hood. Per Sam's agreement, I also renamed this component to <Tabs />.

This component may be modified further once it's being used in actual pages, so this is just a gradual improvement for now.

Copy link

changeset-bot bot commented Jul 23, 2024

⚠️ No Changeset found

Latest commit: fbc96fc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

github-actions bot commented Jul 23, 2024

Visit the preview URL for this PR (updated for commit fbc96fc):

https://penumbra-ui-preview--pr1543-jessepinho-tabs-v2-ap0r1mcc.web.app

(expires Tue, 30 Jul 2024 22:55:36 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 709d729610ef7a6369b23f1cb2b820a60cc685b1

Comment on lines +34 to +38
&:focus-within {
outline: none;
}

&:focus-within::after {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Radix UI's <Tabs /> uses focus-within rather than focus, so this addresses that change.

@jessepinho jessepinho changed the title WIP: Use Radix UI's Tabs component under the hood Use Radix UI's Tabs component under the hood Jul 23, 2024
@jessepinho jessepinho marked this pull request as ready for review July 23, 2024 22:09
@jessepinho jessepinho requested a review from a team July 23, 2024 22:09
@jessepinho jessepinho changed the title Use Radix UI's Tabs component under the hood <SegmentedPicker />: Use Radix UI's Tabs component under the hood Jul 23, 2024
@jessepinho jessepinho marked this pull request as draft July 23, 2024 22:45
@jessepinho jessepinho changed the title <SegmentedPicker />: Use Radix UI's Tabs component under the hood <SegmentedPicker />: Use Radix UI's Tabs component under the hood, and rename to <Tabs /> Jul 23, 2024
*/
value: ValueType;
export interface TabsTab {
value: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Radix UI's <Tabs /> only supports strings as the value type.

@jessepinho jessepinho marked this pull request as ready for review July 24, 2024 20:17
@@ -34,6 +33,6 @@ export const Basic: Story = {

const onChange = (value: { toString: () => string }) => updateArgs({ value });

return <SegmentedPicker {...props} onChange={onChange} />;
return <Tabs {...props} onChange={onChange} />;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (non-blocking, worth implementing): expose TabsContent component from Radix and somehow allow the children for Tabs.

If you inspect the markup of the Radix Tabs example, you can see that Tabs.Content components are nested inside the Tabs.Root. It allows Radix to set useful attributes like data-state="active" and role="tabpanel". Plus, there is a rendering logic involved that all [role="tabpanel"] divs are rendered but inactive divs have empty contents. All of this corresponds to W3C standards.

Developers might and probably will forget to implement this, so it would be useful to help them (and ourselves)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call — will look into it. I'm not sure that <TabsContent /> will be appropriate in our case, since we won't have multiple tab contents rendered on the page at the same time — <Tabs /> will usually be used for routing, I believe. But I created a ticket to look into it nonetheless.

@jessepinho jessepinho merged commit 887e228 into main Jul 26, 2024
8 checks passed
@jessepinho jessepinho deleted the jessepinho/tabs-v2 branch July 26, 2024 16:03
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.

2 participants