Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

fix(uiSelectController) ActiveIndex should skip disabled choises #1848

Merged
merged 10 commits into from Jan 4, 2017

Conversation

Jefiozie
Copy link
Contributor

When pressing key up or/and key down the activeIndex should be set to a item that isn't a disabled choice.
refrence: #1823

shyela pushed a commit to cookbrite/ui-select that referenced this pull request Nov 15, 2016
 - "fix(uiSelectController) ActiveIndex should skip disabled choises"
 - angular-ui#1848
@user378230
Copy link
Contributor

I think we can shorten the logic down to:

...
       case KEY.DOWN:
        if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode
        else if (ctrl.activeIndex < ctrl.items.length - 1) {
          var idx = ++ctrl.activeIndex
          while(_isItemDisabled(ctrl.items[idx]) && idx < ctrl.items.length) {
            ctrl.activeIndex = ++idx;
          }
        }
        break;
      case KEY.UP:
        var minActiveIndex = (ctrl.search.length === 0 && ctrl.tagging.isActivated) ? -1 : 0;
        if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode
        else if (ctrl.activeIndex > minActiveIndex) {
          var idx = --ctrl.activeIndex;
          while(_isItemDisabled(ctrl.items[idx]) && idx > minActiveIndex) {
            ctrl.activeIndex = --idx;
          }
        }
        break;
...

@user378230
Copy link
Contributor

user378230 commented Nov 16, 2016

We also need a test for items being disabled due to being selected, if you wouldn't mind incorporating a test.

Can you just check nothing breaks with tagging enabled and tagging label set to something and also set to false?

Thanks! 😀

switch (key) {
case KEY.DOWN:
if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode
else if (ctrl.activeIndex < ctrl.items.length - 1) { ctrl.activeIndex++; }
else if (ctrl.activeIndex < ctrl.items.length - 1) {
idx = ++ctrl.activeIndex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just declare the var here? I know it leaks out anyway but it makes it clearer where its used then.

@@ -2831,6 +2833,36 @@ describe('ui-select tests', function() {
expect(scope.$model.name).toEqual('Natasha');
expect(el.scope().$select.selected.length).toEqual(2);
});
it('should ignore disable items key up with tagging on false', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should ignored disabled items in the down direction with tagging off

expect(el.scope().$select.activeIndex).toBe(2);
});

it('should ignore disable items key up with tagging on true', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should ignored disabled items going up with tagging on

expect(el.scope().$select.activeIndex).toBe(-1);
});

it('should ignore disable items key down', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as tagging: false, no? Maybe we don't need this test

@@ -3167,4 +3200,58 @@ describe('ui-select tests', function() {
});
});

describe('Test key down key up and activeIndex should skip disabled choice',function(){
it('should ignore disable items key down', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should ignore disabled items, going down

expect(el.scope().$select.activeIndex).toBe(2);
});

it('should ignore disable items key up', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...going up

expect(el.scope().$select.activeIndex).toBe(2);
});
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename this tests too? Like how I did the others. Thank youu! 😄

@user378230
Copy link
Contributor

@Jefiozie thanks for the amazing work, as always!

When you have a chance can you add a test for multiple select with remove-selected="false" and ensure it skips those items as well? (The remove-selected means that items still remain in the select list after a user has selected them, they are just disabled. I think items are more likely to be disabled this way than using the disable expression.

@Jefiozie
Copy link
Contributor Author

As requested the extra tests and changes to the idx check.

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Dec 4, 2016

@user378230 , Any ideas when this will be merged?

@Jefiozie
Copy link
Contributor Author

@user378230 & @aaronroberson , any idea when this will be merged?

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Jan 4, 2017

@user378230 & @aaronroberson , any idea when this will be merged?

@aaronroberson aaronroberson merged commit 531e4b3 into angular-ui:master Jan 4, 2017
@aaronroberson
Copy link
Contributor

Done! Thanks @Jefiozie

@Jefiozie Jefiozie deleted the 1823 branch March 21, 2017 07:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants