-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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(Dropdown): support disabled items #482
feat(Dropdown): support disabled items #482
Conversation
@jcarbo Your second option can be achieved by listening on the |
We can detect click inside/outside of a node, but this requires a As much as I don't like to do so, I think we add the inline style. Then, we can simply add the style in // renderOptions() map() Dropdown.Item
style={{ ...opt.style, pointerEvents: 'all' }}
// handleItemClick()
const item = this.getItemByValue(value)
if (multiple || item.disabled) {
e.nativeEvent.stopImmediatePropagation()
} |
Inline comments are much appreciated anywhere there is odd or special case handling like this. Thanks in advance. |
4b2ea2b
to
1b448bd
Compare
Current coverage is 98.63% (diff: 100%)@@ master #482 diff @@
==========================================
Files 101 101
Lines 1453 1465 +12
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 1433 1445 +12
Misses 20 20
Partials 0 0
|
Thanks for the feedback. I've implemented the inline-style option. As much as I hate inline styles, it was significantly simpler than dealing with the DOM. Clicking a disabled item now just does nothing and keeps the menu open. Let me know if there's anything else this is missing. |
title='Disabled Item' | ||
description='A disabled dropdown item does not allow user interaction' | ||
examplePath='modules/Dropdown/States/DisabledItem' | ||
/> |
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.
Left some inline comments. If we could get a test that asserts disabled items can never be selected, then we can forgo the test asserting they aren't made active on Enter. Since, we'd also need to ensure they aren't made active on blur. |
6b47f45
to
fa7de43
Compare
Implemented the remaining feedback, namely preventing disabled elements from being selected. If all elements are disabled, the Actually found a bug and another broken test: |
Thanks much, released in |
Addresses #478
I added code that should handle ignoring a click on the dropdown item and keeping the menu open. However, the onClick is never getting called so the event is bubbling to the
Dropdown
element itself which is toggling it's visibility.Is there some magic happening somewhere that disables clicks on an element with
disabled
passed as props? As you can see, it's not being applied onto the element. It's just being used to add thedisabled
class.EDIT AHH it's
pointer-events: none;
😞 . Thoughts on how to handle this? Two ideas:handleClick
function, check if the click was within the menu (can you even do that with synthetic events?) and ignore it.I don't love either of those idea, tbh.