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

feat(dropdown): support programatic trigger, toggle callback & esc key #1616

Closed
wants to merge 3 commits into from

Conversation

bekos
Copy link
Contributor

@bekos bekos commented Jan 19, 2014

No description provided.

@bekos
Copy link
Contributor Author

bekos commented Jan 20, 2014

@angular-ui/bootstrap Anyone willing for a code review?

This is basically a refactor, but I tried not to introduce any breaking change. The idea is to make the dropdown element as the main directive, and dropdownToggle is just an optional directive that hooks in dropdown's controller to change it's state.

@chrisirhc
Copy link
Contributor

Took a quick look. Will read in more detail later tonight. How about using the element's blur event instead? And perhaps triggering blur on escape?

});

it('should close on $location change', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we have the need to test that isopen is false when the event is triggered?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line is removed. This test is moved at line 67.

@Foxandxss
Copy link
Contributor

👍 for me. Extra stuff that is useful, non-breaking and with no overhead. Why not? :)

@bekos
Copy link
Contributor Author

bekos commented Jan 20, 2014

@chrisirhc This seems reasonable, I need to investigate though :-)

@bekos
Copy link
Contributor Author

bekos commented Jan 20, 2014

@chrisirhc Checked with bootstrap and they also use document click to hide the menu. This way you can navigate on the page with tab without closing the dropdown. Is there any specific issue you see that we should not use document click?

}
};

var documentClickBind = function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly rename this to closeDropdown.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, probably I should extract the

openScope.$apply(function() {
      openScope.isOpen = false;
    });

into a closeDropdown function and call from the bindings.

@chrisirhc
Copy link
Contributor

Ah you're right, somehow I had the impression that tab should dismiss the dropdown toggle, but I was wrong.

};

this.toggle = function() {
$scope.isOpen = !$scope.isOpen;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should take in an argument open and check if arguments are 0:

if (arguments.length) {
  return $scope.isOpen = !!open;
} else {
 return $scope.isOpen = !$scope.isOpen;
}

This way it can handle an argument that sets the open explicitly and it also returns the actual value after the toggle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's nice, but there was no use case for this. See test coverage report :-D
Do you want to add as future proof solution in case someone wants to hook on the controller, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

@bekos I like @chrisirhc's idea. Use-case: Perhaps there's a tutorial where it says "When you click here, this dropdown will open!".

and you want to make sure it actually stays open and doesn't close if the user already had it open.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ajoslin The toggle method is not exposed to the directive. It is only used by the dropdown toggler to do the toggling.
I have added in the demo a button that does what you say, by just setting the is-open to true.
I think @chrisirhc is wanting this in case another directive wants to use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will make the change anyway :-)

@bekos
Copy link
Contributor Author

bekos commented Jan 21, 2014

Thanks for the review! I will change the issues mentioned and merge it. I would also rename the module from dropdownToggle to dropdown as this is now the main directive, if of course there are no objections.

@bekos
Copy link
Contributor Author

bekos commented Jan 21, 2014

Landed on master.

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.

5 participants