-
-
Notifications
You must be signed in to change notification settings - Fork 451
fix: preserve default className when className is null or undefined #599
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
base: main
Are you sure you want to change the base?
fix: preserve default className when className is null or undefined #599
Conversation
danez
left a comment
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.
Thanks for the PR.
I left some comments.
| // Only pass valid DOM attributes and data- attributes | ||
| const domAttributes = {}; | ||
| Object.keys(restProps).forEach((key) => { | ||
| if ( | ||
| key.startsWith('data-') || | ||
| key === 'id' || | ||
| key === 'style' || | ||
| key === 'title' || | ||
| key === 'role' || | ||
| key === 'tabIndex' || | ||
| key === 'aria-label' || | ||
| key === 'aria-labelledby' || | ||
| key === 'aria-describedby' || | ||
| key === 'aria-controls' || | ||
| key === 'aria-selected' || | ||
| key === 'aria-disabled' | ||
| ) { | ||
| domAttributes[key] = restProps[key]; | ||
| } | ||
| }); |
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.
This domAttributes is not needed. We remove all custom props above and pass on everything else.
| // Only pass valid DOM attributes and data- attributes | |
| const domAttributes = {}; | |
| Object.keys(restProps).forEach((key) => { | |
| if ( | |
| key.startsWith('data-') || | |
| key === 'id' || | |
| key === 'style' || | |
| key === 'title' || | |
| key === 'role' || | |
| key === 'tabIndex' || | |
| key === 'aria-label' || | |
| key === 'aria-labelledby' || | |
| key === 'aria-describedby' || | |
| key === 'aria-controls' || | |
| key === 'aria-selected' || | |
| key === 'aria-disabled' | |
| ) { | |
| domAttributes[key] = restProps[key]; | |
| } | |
| }); |
| return ( | ||
| <div | ||
| {...attributes} | ||
| {...domAttributes} |
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.
| {...domAttributes} | |
| {...attributes} |
| environment, // unused here | ||
| disableUpDownKeys, // unused here | ||
| disableLeftRightKeys, // unused here | ||
| ...restProps |
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.
| ...restProps | |
| ...attributes |
| const className = | ||
| propClassName == null ? defaultProps.className : propClassName; |
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.
| const className = | |
| propClassName == null ? defaultProps.className : propClassName; | |
| const className = propClassName ?? defaultProps.className; |
What does this PR do?
Preserves the default
react-tabsclassName inUncontrolledTabswhenprops.classNameisundefinedornull.Why?
Currently, spreading
{ ...defaultProps, ...props }causes an explicitundefinedornullclassName to override the default, which breaksbackward compatibility and styling.
Maintainers confirmed this behavior in #581.
What’s included
undefined/nulloverridesRelated issue
Fixes #581