question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to disable item selection?

See original GitHub issue
  • downshift version: 1.28.0
  • node version:
  • npm (or yarn) 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:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kentcdoddscommented, Mar 5, 2018

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!

0reactions
kentcdoddscommented, Mar 6, 2018

Yes please!

Read more comments on GitHub >

github_iconTop 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 >
How to show disable HTML select option in by default?
Use hidden . <select> <option ...
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found