-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
fix(Accordion): Use empty SelectableContext to prevent dropdown from closing accordion #5201
fix(Accordion): Use empty SelectableContext to prevent dropdown from closing accordion #5201
Conversation
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.
cc @jquense does this API change make sense to you?
src/NavDropdown.js
Outdated
}); | ||
|
||
return ( | ||
<Dropdown ref={ref} onSelect={handleSelect} {...props} as={NavItem}> |
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 wonder if we want to make as
customizable in this context, then.
with this change, rendering a <Dropdown>
with whatever styling inside a <Nav>
now won't do the same thing as rendering a <NavDropdown>
which is probably okay, but maybe a bit more customizability here would help
@taion, I just revisited this and I realized anything that implements ie. in AccordionCollapse.js
What do you think? |
That could work. We might want to do that in general wherever we consume this context, then? Could also use a different context here, but I guess that'd be breaking. I'm not sure. Is it definitely the case that |
TBH, I can't think of any case where elements within the collapse would want to trigger the accordion parent. |
well, it's sort of like nested navigation... idk we can try that out, though |
I'll update the PR anyway since the original solution doesn't cover all cases. Others can chime in and we can close this if it's no good. |
@taion Any ETA on getting this merged? |
I'm a bit concerned this change will break anyone using a custom dropdown in a navbar. I think maybe the underlying issue is we are reusing SelectableContext when we should probably have a different SelectableContext "instances" for each, lack of a better word, group of selectable behaviors. Then the contexts would talk past each other but maintain a unified public interface. something like: NavSelectableContext = createSelectableContext();
AccordianSelectableContext = createSelectableContext() |
Oh, that sounds reasonable to me. Can we make that change for v1, though, or does it need to be deferred for v2? |
I think this can go into a v1, it is maintaining the same API, and fixes a bug...is the SelectionContext public? |
It's not explicitly documented nor exposed at top-level. I think we may have pointed people toward it for cases where they need more fine-grained control, though. |
Oops I forgot to update the title here - it no longer reflects the new change. What I ended up doing is wrapping the AccordionCollapse with a null SelectableContext. This prevents the elements inside the collapse from grabbing the context. Looking at the code I believe the only element that uses SelectableContext is the toggle. I don't think the contents of the collapse need the root SelectableContext from Accordion.... does it? |
…closing accordion
5847a0f
to
3b520a6
Compare
Thanks for this fix! Any chance of a 1.3.1 release soon with this included? |
@taion friendly ping for a new release sometime :) |
@tmm1 this is available in 1.4.0 |
Thanks! I missed that on https://github.com/react-bootstrap/react-bootstrap/releases |
Fixes #4176
I moved the
SelectableContext
consumption toNavDropdown
because it looks like this context is used in conjunction withNav
in triggeringonSelect
forNavDropdown
s.I've added the test in
Nav
to make sure I didn't break anything in that API and another test inAccordion
to make sure the a dropdown would not trigger the accordion context.This would also close the PR #4772.