Skip to content

Custom tabpanel selected class #149

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

Conversation

alexanderwallin
Copy link

This PR does the following:

  1. It lets you override the class name to use for currently selected <TabPanel>s using a new selectedClassName prop;
  2. it only applies display: none; to the <TabPanel> if a custom selectedClassName prop has not been provided; and
  3. adds tests.

My use case is that I need to keep the contents of hidden tabs and give them a bunch of styles in order to maintain the parent's dimensions.

@@ -24,28 +25,37 @@ module.exports = React.createClass({
getDefaultProps() {
return {
selected: false,
selectedClassName: null,
Copy link

Choose a reason for hiding this comment

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

selectedClassName: 'ReactTabs__TabPanel--selected'

Copy link
Author

Choose a reason for hiding this comment

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

This is null in order to satisfy inline styles condition on line 42.

Copy link
Author

Choose a reason for hiding this comment

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

Although I do think it is too much implicit logic going on.

const {
id, tabId, selected,
className, selectedClassName, style, children,
...attrs,
Copy link

Choose a reason for hiding this comment

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

why did you change this?

Copy link
Author

Choose a reason for hiding this comment

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

The line got 105 characters long, which didn't pass the linting.

...attrs,
} = this.props;

// Only hide using inline styles if `selectedClassName` isn't provided
Copy link

Choose a reason for hiding this comment

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

why?

Copy link
Author

Choose a reason for hiding this comment

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

The idea is that if you specify your own custom classes, you want control over hiding/showing. With inline styles you would have to override using !important.

Copy link
Author

Choose a reason for hiding this comment

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

We could also just follow the design of the Tab component which only uses overridable classes.

The case I ran into was that I needed hidden TabPanels to still take up their natural height, i.e. setting visibility: hidden; instead on the inline display: none;.

@danez danez mentioned this pull request Apr 24, 2017
@danez danez closed this in #168 Apr 24, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants