Is there a way to disable item selection?
See original GitHub issuedownshift
version: 1.28.0node
version:npm
(oryarn
) version:
Problem description:
Is there a way to disable the selection of an item based on some conditionals from the dropdown so that onSelect
or onChanged
doesn’t gets triggered?
Methods tried:
I’ve tried using stateReducer
, however after pressing enter on an item that I want to disable, the dropdown loses focus and the keyboard arrow keys stops working.
function stateReducer(state, changes) {
switch (changes.type) {
case Downshift.stateChangeTypes.keyDownEnter:
case Downshift.stateChangeTypes.clickItem: {
// Basically I want to disable the selection of certain items.
// something like event.preventDefault();
const isRegistered = selectedItem.isRegistered;
if (isRegistered) {
return {
...changes,
selectedItem: null,
inputValue: state.inputValue,
isOpen: state.isOpen,
highlightedIndex: state.highlightedIndex,
};
}
return changes;
}
default:
return changes;
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
How to disable selected items inside gallery
You can do that using the DisplayMode property of the button. Set your condition for it to be either Edit or Disabled. If(condition1=Somevalue, ......
Read more >How to disable item selection in the WinRT GridView
Demonstrates how you can disable selection of Windows 8.1 GridView items dynamically by using a DataTemplateSelector.
Read more >List - How to disable selection of a particular item
You can set the disabled option of a particular item to true. In this case, the item will be disabled and you will...
Read more >How can I use "Disable Items for Selection" in my situation?
In such case I would recommend you to open developers tool and inspect the id of the Kendo DropDownList input element and check...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @cusxio!
Thanks @Antontelesh and @austintackaberry for all your help here!
Hmmm… Make sure you’re on the latest version? Though that’s probably not it…
We do have support for disabling the input and the button with their respective prop getters. It makes sense to me that we’d add support for items as well…
So I’m going to go ahead and say let’s accept a PR to support this. All it really takes is to not return any of the event handlers if
disabled
is true. You can see the other similar implementations for a nice way to accomplish this.Thanks!
Yes please!