-
Notifications
You must be signed in to change notification settings - Fork 560
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
tabs: Add support for vertical orientation #486
Conversation
Thank you for the pull request |
packages/tabs/src/index.tsx
Outdated
orientation === "vertical" | ||
? isRTL | ||
? event.key === "ArrowLeft" | ||
: event.key === "ArrowRight" |
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.
One thing I'm just realizing: this doesn't take into account the relative order of TabsList and TabPanels. For instance:
<Tabs orientation="vertical">
<TabPanels>
<TabPanel>
<h1>one!</h1>
<p>Here's some example content.</p>
<button>yo</button>
</TabPanel>
<TabPanel>
<h1>two!</h1>
<p>Here's some example content.</p>
</TabPanel>
<TabPanel>
<h1>three!</h1>
<p>Here's some example content.</p>
</TabPanel>
</TabPanels>
<TabList>
<Tab>One</Tab>
<Tab>Two</Tab>
<Tab>Three</Tab>
</TabList>
</Tabs>
Assuming we're in LTR mode, TabPanels will show up on the left (which is correct), but the left arrow key won't focus the panel.
I'll think about how to address that, but let me know if you all have any ideas. Could actually be a good reason to make the options more explicit as @chancestrickland mentioned in his TODO i.e. horizontal-top
, horizontal-bottom
, 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.
I took a shot at detecting the relative order (while still taking isRTL into account) in f07be1d.
website/src/pages/tabs.mdx
Outdated
@@ -143,7 +144,7 @@ function Example() { | |||
onChange={index => setTabIndex(index)} | |||
style={{ | |||
color: "white", | |||
background: backgroundColor | |||
background: backgroundColor, |
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.
Oops, my local Prettier config might have interfered here. I'll revert these comma changes.
EDIT: Scratch that, looks like this is correct:
Line 175 in 9bc8e3e
"trailingComma": "es5" |
Still, I'm happy to revert the comma changes if you need me to!
@@ -91,6 +91,7 @@ Please see the [styling guide](/styling). | |||
| [onChange](#tabs-onchange) | function | false | | |||
| [defaultIndex](#tabs-defaultindex) | number | false | | |||
| [index](#tabs-index) | number | false | | |||
| [orientation](#tabs-orientation) | string | false | |
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.
Is string
enough for the type here? Or should I make it more specific, a la line 250?
Looks like a solid start, thanks for the PR! I'll dig into this a bit next week and see what we can do. |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 8ce9450:
|
Hey @chancestrickland! The tests are now running through, so this PR is (finally) ready for a proper review whenever you get a chance |
Thanks so much for this! Finally got around to reviewing, and it looks great. I made some adjustments to the API. Mainly,
The reason here is that I'd rather be explicit vs. checking children to see whether TabList or TabPanels comes first, which can break certain composition patterns. We could register refs similar to how we do for tab descendants, but a single prop change at the top along with added documentation to explain the distinctions seems simple enough for this purpose. App code can abstract this further if someone doesn't like it. |
Slept on it, and now I'm having second thoughts. I'm going to seek some feedback on this approach. |
@chancestrickland No problem, and definitely no rush given everything that's going on right now. In any case, let me know if there's anything I can do to help gather feedback! |
Hey folks 👋
This PR adds a new
orientation
prop to the Tabs component and sets its default to"horizontal"
. The new prop has these effects:aria-orientation
attribute to the TabsList DOM element per the WAI-ARIA docs.orientation
has a default, that means the existing tab examples also get this new attribute."vertical"
:I did see this TODO:
reach-ui/packages/tabs/src/index.tsx
Lines 17 to 21 in 9bc8e3e
This PR takes a slightly different approach, by limiting the options to just "horizontal" and "vertical" and then relying on RTL (or just the ordering of TabsList and TabPanels) for the rest. Let me know what you think!
I'm opening this as a draft PR, because I'm still trying to figure out what's going on with the tests, but I wanted to get some feedback on the approach so far.
Screenshots
PR template
Thank you for contributing to Reach UI! Please fill in this template before submitting your PR to help us process your request more quickly.
yarn test
).yarn start
).This pull request:
If creating a new package:
examples
directorysrc
directory with anindex.tsx
entry filestyle.css
file (if needed by the new package)