-
Notifications
You must be signed in to change notification settings - Fork 15
feat(accordion)!: add sections prop #572
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
geotrev
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.
Happy to chat in more depth if anything is unclear. Thanks
|
|
||
| const isControlled = expandedSections !== null && expandedSections !== undefined; | ||
| const [expandedState, setExpandedState] = useState<Value[]>( | ||
| defaultExpandedSections || expandedSections || sections.slice(0, 1) |
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.
Why is this falling back to an expansion state on the first section? Feels like we should be accepting undefined as a valid state.
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.
Could you explain more on this? expandedState does have dependents (like disabledState, etc) which does need it to be an Array in certain conditions.
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.
Not strictly related to JZ's comment, but I would expect expandedSections to come before defaultExpandedSections - controlled value takes priority, and the default as the fallback, if given.
Getting back to JZ's comment, I'm curious on the thinking there as well. Not opposed to it, but keeping the type consistent does help with the internal logic type reliability from the get go. I could also see defaultExpandedSections having a default arg value of [] to make it simpler.
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.
Lines 31-36 use the internalExpandedState which resolves to the expandedSections before defaultExpandedSections 😄:
// lines 31-36
const isControlled = expandedSections !== null && expandedSections !== undefined;
const [expandedState, setExpandedState] = useState<Value[]>(
defaultExpandedSections || sections.slice(0, 1)
);
const [disabledState, setDisabledState] = useState(collapsible ? [] : expandedState);
const internalExpandedState = getControlledValue(expandedSections, expandedState)!;On the second point, it will change the logic indeed.
geotrev
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.
I like the closer alignment with with other containers a la sections. Other than JZ's remaining comments, it's looking much better!
jzempel
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.
looks good, @Francois-Esquire
Description
Adds a new
sectionsprop to explicitly define each section. Moving forward,sectionswill be needed for theuseAccordioncontainer to work properly. There have been additional changes to the distribution exports.Checklist
yarn start)includes new unit tests