Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reordering aggregation priority by keyboard #13635

Merged
merged 4 commits into from
Aug 25, 2017

Conversation

timroes
Copy link
Contributor

@timroes timroes commented Aug 22, 2017

To make the reordering of priorities of aggregations keyboard accessible, this PR introduces the keyboardMove directive. While the drag button has keyboard focus, you can press the up and down key to move the aggregation up and down in the priority list.

To explain the $timeout(() => element.focus()): When reordering items in an ng-repeat it will need to remove the element from DOM and reattach it at another position. When the aggregation moved down in the priority list, it wasn't detached from DOM and thus the focus was kept on the button, when moving it upwards it was reattached and thus the focus was lost after one move. To be able to move the aggregation multiple positions up without needing to tab to the button again, I focus the button again in the next execution cycle, when it is reattached to the DOM.

Fixes #11858

@timroes timroes added Project:Accessibility Feature:Vislib Vislib chart implementation Feature:Visualizations Generic visualization features (in case no more specific feature label is available) review labels Aug 22, 2017
@ppisljar
Copy link
Member

works well, but would it be possible to also activate this on mouse click ? (set focus to the button?)

@timroes
Copy link
Contributor Author

timroes commented Aug 22, 2017

@ppisljar It's not as easy as I thought. The drag library, that we use dragula is currently preventing focusing the buttons on click (https://github.com/bevacqua/dragula/blob/master/dragula.js#L113). We would need to work around this, by writing some directive, that just focuses an element on mousedown. That way we could steal the focus back. Due to the order in which events get resolved, this would also mean, that we need to add an pointer-events: none to the inner icon. This sounds like a lot of workarounds/hacks for me to get this working. Do you think we should use that many hacks or rather yield up the mouse focus of the button?

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

This is fantastic!! Great job, Tim! I had a couple small suggestions but this is beautiful.

down: 'down'
};

const directionMapping = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider importing these keycodes from the UI Framework instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes totally sense. I just found, that we currently have mixed ways of exporting keycodes in the ui_framework services. That's why I created another PR (#13663). If you feel like that refactoring is a good thing, you could review that PR please, and I would rebase this PR as soon as I merged the other one to use the exported keycodes.

};

uiModules.get('kibana')
.directive('keyboardMove', ($timeout) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

How about renaming this to onKeyboardMove to reflect its role as an event handler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this directive really adds some logic to an element, and doesn't just listen on an event, that would anyway happen, I would rather not rename it onKeyboardMove. A directive named on- sounds for me side effect free, which this isn't. Besides Angular itself not naming any of the listeners on-, but just ng-keydown, etc.

Would you be up for discussion on this topic?

.directive('keyboardMove', ($timeout) => ({
restrict: 'A',
scope: {
keyboardMove: '&'
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm worried about this isolate scope. If we apply this to an element which has its own isolate scope, they'll conflict. I think it would be better to use $parse to extract a reference to the callback, similar to the way ngClick does it: https://github.com/angular/angular.js/blob/master/src/ng/directive/ngEventDirs.js#L60

@thomasneirynck
Copy link
Contributor

jenkins, test this

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Looks good! Merge-worthy once you merge and rebase your keyCodes PR.

@timroes timroes force-pushed the keyboard-reordering branch from ab5bed8 to 99dac56 Compare August 24, 2017 19:32
Copy link
Contributor

@aphelionz aphelionz left a comment

Choose a reason for hiding this comment

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

LGTM

@timroes timroes merged commit c96481d into elastic:master Aug 25, 2017
@timroes timroes deleted the keyboard-reordering branch August 25, 2017 08:11
timroes added a commit that referenced this pull request Aug 25, 2017
* Make aggs sortable by keyboard, fix #11858

* Add keyboard_move tests

* Use $parse instead of creating a child scope

* Use keyCodes from ui_framework
@timroes
Copy link
Contributor Author

timroes commented Aug 25, 2017

Backports:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Vislib Vislib chart implementation Feature:Visualizations Generic visualization features (in case no more specific feature label is available) Project:Accessibility release_note:enhancement v6.1.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants