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(theme-classic): allow passing additional attributes to tab headings #6082

Merged
merged 5 commits into from
Dec 17, 2021

Conversation

Drylozu
Copy link
Contributor

@Drylozu Drylozu commented Dec 10, 2021

Motivation

It's nice that we can customize the tabs of Tabs component with CSS or just to be able to differentiate them (in CSS you can't select elements by their inner HTML). And I think this is the best way to be able to do this because if we use className attribute, Tabs and TabItem components already have one on it and the one from TabItem component places it to it's content and not it's tab.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

This adds a data-value attribute to the Tabs component, knowing that they must be unique there should be no problem.

image
image

We should be able to style a specific tab whether it's active or not, using the aria-selected attribute or tabs__item--active class:
image

There are infinite possibilities, designs and styles. For example, being able to place a red color in the Apples tab and an orange color in the Oranges tab of the Tabs example :)!

@netlify
Copy link

netlify bot commented Dec 10, 2021

✔️ [V2]
Built without sensitive environment variables

🔨 Explore the source changes: 10e8e85

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/61bc6394e9cfd70007f9fc49

😎 Browse the preview: https://deploy-preview-6082--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Dec 10, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟢 Performance 94
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-6082--docusaurus-2.netlify.app/

@Josh-Cena
Copy link
Collaborator

That adds one extra level of indirection IMO. What are the benefits of this approach compared to, say, we letting you pass custom props to the tab headings?

@armano2 May I know what's your point of objection?

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Dec 10, 2021
@slorber
Copy link
Collaborator

slorber commented Dec 10, 2021

I don't like it much, we'd rather let you provide custom attributes instead and build this yourself, something like:

<Tabs
  defaultValue="apple"
  values={[
    {label: 'Apple 1', value: 'apple',data-value: 'xyz', className: 'myClassName'},
  ]}>

Maybe we can also add something so that using <TabItem> would allow to apply props to the parent?

@Drylozu
Copy link
Contributor Author

Drylozu commented Dec 12, 2021

I don't like it much, we'd rather let you provide custom attributes instead and build this yourself.
Maybe we can also add something so that using <TabItem> would allow to apply props to the parent?

I like this idea, should I close this PR and do a new one? How will we provide the custom props to <TabItem>?

@Josh-Cena
Copy link
Collaborator

I like this idea, should I close this PR and do a new one?

Just edit on the current PR. At least for me personally I don't like PRs closed unmerged in my timeline...

How will we provide the custom props to <TabItem>?

Spreading the rest props. But I think we are spreading them to the tab headings, not Tab items.

@Drylozu
Copy link
Contributor Author

Drylozu commented Dec 15, 2021

I think it's ready. I created a prop called attributes in the Tabs values/TabItem because if we use the spread operator directly, some props like default or mdxType (in .mdx files) would be added, and they would be things that we don't want I guess

@Josh-Cena
Copy link
Collaborator

👍I see, had just been wondering why :P LGTM

@Josh-Cena Josh-Cena added the pr: new feature This PR adds a new API or behavior. label Dec 15, 2021
@Josh-Cena Josh-Cena changed the title feat(theme-classic): add data-value attribute to Tabs feat(theme-classic): allow passing additional attributes to tab headings Dec 15, 2021
@slorber
Copy link
Collaborator

slorber commented Dec 15, 2021

That seems fine

Wonder if you could add an example in one of our docs for dogfooding and easier review: see website/_dogfooding (coloring tabs with CSS looks nice)

I also agree to use a custom prop instead of spreading everything, we should allow to pass props to both the parent and the child in the end, it allows more use-cases

Is there a better name that we can find instead of attributes? I find it not very intuitive that it will be props to the parent? Maybe tabAttributes? 🤷‍♂️ I don't have better for now

@Drylozu
Copy link
Contributor Author

Drylozu commented Dec 15, 2021

Wonder if you could add an example in one of our docs for dogfooding and easier review: see website/_dogfooding (coloring tabs with CSS looks nice)

I'll try but I don't know how to do that

Is there a better name that we can find instead of attributes? I find it not very intuitive that it will be props to the parent? Maybe tabAttributes? 🤷‍♂️ I don't have better for now

I think tabAttributes is fine but what do you think about headerAttributes?


Should I add something like allow functions to know if the current tab is active?

@Josh-Cena
Copy link
Collaborator

I don't find it very unintuitive that attributes apply to the heading... In the end everything we can customize are the headings anyways and the TabItem themselves are just dummy elements

@Josh-Cena Josh-Cena added the status: awaiting review This PR is ready for review, will be merged after maintainers' approval label Dec 17, 2021
@slorber
Copy link
Collaborator

slorber commented Dec 17, 2021

Thanks, that looks nice.

In the end everything we can customize is the headings anyways and the TabItem themselves are just dummy elements

TabItem is not a dummy element, it's a div[role="tabpanel]. By providing props here, we might want to either customize the tab item, or that tab panel. Current API looks good to me.

@slorber slorber merged commit fa3926e into facebook:main Dec 17, 2021
@Josh-Cena Josh-Cena removed the status: awaiting review This PR is ready for review, will be merged after maintainers' approval label Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants