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

feat(dropdown) Add keynav support (fix for #1228) #3685

Closed
wants to merge 1 commit into from

Conversation

bleggett
Copy link
Contributor

Adds a new option flag to the dropdown class that enables the use of arrow keys to navigate dropdown list elements, like non-angular bootstrap does. Added tests and updated doc with example. Fix for #1228 and based off of #3212

@bleggett bleggett changed the title Dropdown keynav (fix for #1228) feat(dropdown) Add keynav support (fix for #1228) May 24, 2015
@rvanbaalen
Copy link
Contributor

Please squash your commits.

@rvanbaalen rvanbaalen added this to the Backlog milestone Jun 2, 2015
@bleggett
Copy link
Contributor Author

bleggett commented Jun 3, 2015

Squashed.

self.selectedOption+1);
}
}
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be inside the case statement?

Copy link
Contributor

Choose a reason for hiding this comment

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

You're saying

var elems = self.dropdownMenu ? //If append to body is used.
      (angular.element(self.dropdownMenu).find('a')) :
     (angular.element(self.$element).find('ul').eq(0).find('a'));

should be copied to each of these case's?

Pro; code gets executed when it should
Con; duplicate code

I guess the pro is better than the con.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean the break

Copy link
Contributor

Choose a reason for hiding this comment

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

Of course.

A break statement terminates execution of the smallest enclosing switch or iteration statement.

So I would vote to put these breaks inside the curly brackets as well.

@wesleycho
Copy link
Contributor

These are mostly code style issues. @rvanbaalen if you think it's worth merging and fixing these issues before pushing up, this PR LGTM.

} else {
self.selectedOption = (self.selectedOption === elems.length -1 ?
self.selectedOption :
self.selectedOption+1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Add spaces before and after the +.

Also make the indentation only one level deep, and not align to the self in the first line.

@RobJacobs
Copy link
Contributor

My only concern is with setting focus() on the menu item elements, I'm not sure if this would disrupt the tab flow once the dropdown is closed? The typeahead has similar functionality but is uses an activeIndex with:

ng-class="{active: isActive($index) }"

to decorate the element. Then listens for enter to trigger selection.

@rvanbaalen rvanbaalen removed their assignment Jun 4, 2015
@rvanbaalen
Copy link
Contributor

@bleggett Can you incorporate these suggestions?

@bleggett
Copy link
Contributor Author

bleggett commented Jun 4, 2015

@rvanbaalen Yep, will do. Will look at what typeahead is doing like @RobJacobs suggested as well.

@wesleycho
Copy link
Contributor

Can you squash your commits again? In the future, if you need to sync up with remote master, you can do git pull --rebase origin master (assuming origin is pointing to this repository)

@bleggett bleggett force-pushed the dropdown-keynav branch 3 times, most recently from 99675b8 to a84966f Compare June 11, 2015 03:03
fix(dropdown): Fixed indexing corner cases and filter key events.

fix(dropdown): Try using document.bind instead

fix(dropdown): Add optional attrib for keyboard-nav.

fix(dropdown): Dedup code and handle differences if dropdown-menu used

fix(dropdown): Fix focus issue and add more tests

fix(dropdown): Update docs with example

fix(dropdown): Revert accidental change to misc/demo/index.html

fix(dropdown): Dedup code and handle differences if dropdown-menu used

Add keynav support to dropdown (angular-ui#1228)

fix(dropdown): Fixed indexing corner cases and filter key events.

fix(dropdown): Try using document.bind instead

fix(dropdown): Add optional attrib for keyboard-nav.

fix(dropdown): Fix focus issue and add more tests

fix(dropdown): Revert accidental change to misc/demo/index.html

fix(dropdown): Dedup code and handle differences if dropdown-menu used

fix(dropdown): Update docs with example

feat(dropdown): Add keynav support (fix for angular-ui#1228)

feat(dropdown): Fix indentation issues and correct breaks.

fix(dropdown): undo indent goofyness.
@bleggett
Copy link
Contributor Author

@wesleycho Yeah, resquashed. Still getting familiar with git, so forgive the rookie mistakes.

Regarding @RobJacobs suggestion: typeahead creates the menu element dynamically, and so can add attrs to it (like the select and activeIndex) relatively easily.

Dropdown relies on a predefined, user-defined menu element, and I'm less sure about tacking attrs onto that blindly, or expecting users to add this stuff themselves.

Am I way off here?

@RobJacobs
Copy link
Contributor

@bleggett Thanks for looking at that, I agree with your assessment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants