2

When options are initially displayed the first item has the active class applied.

To me this makes good sense if search is not toggled, although if the intention is for users to primarily use the search functionality, applying the active class seems clunky – particularly if you are using grouped items and applying custom styles to the drop down content.

The ability to navigate through the items with arrow keys is still desirable, but should only appear when the user initiates.

It does not seem any means to stop this default behaviour exists, I'm simply looking for a way to have an initial state of no active item.

luckyape
  • 722
  • 8
  • 22

2 Answers2

1

I had a similar need and I simply set $select.activeIndex = -1 on focus of the primary element. This stopped the default behavior of the active class being set when the dropdown is loaded

Jason P
  • 66
  • 3
1

I was able to remove the active class from the first item in the dropdown using the uis-open-close attribute on the parent element.

define the attribute in the template:

<ui-select theme="selectize" uis-open-close="$ctrl.setActiveIndex($select)">

Then in the controller set the activeIndex to -1:

setActiveIndex($select) {
    $timeout(() => {
        if($select.selected === undefined) {
            $select.activeIndex = -1;
        }
    }, 25);
}
Craig Wheeler
  • 71
  • 2
  • 6