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

Improve Dev Tools accessibility #13496

Merged
merged 4 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/core_plugins/console/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<div id="editor_actions">
<kbn-tooltip text="click to send request">
<a
kbn-accessible-click
class="editor_action"
ng-click="sendSelected()"
data-test-subj="send-request-button">
Expand All @@ -27,10 +28,10 @@
aria-labelledby="consoleRequestOptions"
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 change this element to a <button> too?

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 assume, you doesn't mean the ul, but got confused with the lines (most likely because GitHub collapsed the code in the middle of the element :D) I anyway made both a.editor-action also into buttons.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops yep that's what I meant! Thanks.

>
<li role="menuitem">
<a class="link" id="copy_as_curl">Copy as cURL</a>
<button class="link" id="copy_as_curl">Copy as cURL</button>
</li>
<li role="menuitem">
<a ng-click="autoIndent($event)">Auto indent</a>
<button ng-click="autoIndent($event)">Auto indent</button>
</li>
</ul>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.run(function (Private, $rootScope) {
};
});

module.controller('SenseController', function SenseController(Private, $scope, $timeout, $location, docTitle) {
module.controller('SenseController', function SenseController(Private, $scope, $timeout, $location, docTitle, kbnUiAceKeyboardModeService) {
docTitle.change('Console');

$scope.topNavController = Private(SenseTopNavController);
Expand All @@ -28,6 +28,7 @@ module.controller('SenseController', function SenseController(Private, $scope, $
output = initializeOutput($('#output'));
input = initializeInput($('#editor'), $('#editor_actions'), $('#copy_as_curl'), output);
init(input, output, $location.search().load_from);
kbnUiAceKeyboardModeService.initialize($scope, $('#editor'));
});

$scope.sendSelected = () => {
Expand Down
50 changes: 50 additions & 0 deletions src/ui/public/accessibility/__tests__/kbn_ui_ace_keyboard_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,53 @@ describe('kbnUiAceKeyboardMode directive', () => {
});

});

describe('kbnUiAceKeyboardModeService', () => {
let element;

beforeEach(ngMock.module('kibana'));

beforeEach(ngMock.inject(($compile, $rootScope, kbnUiAceKeyboardModeService) => {
const scope = $rootScope.$new();
element = $compile(`<div ui-ace></div>`)(scope);
kbnUiAceKeyboardModeService.initialize(scope, element);
}));

it('should add the hint element', () => {
expect(element.find('.uiAceKeyboardHint').length).to.be(1);
});

describe('hint element', () => {
it('should be tabable', () => {
expect(element.find('.uiAceKeyboardHint').attr('tabindex')).to.be('0');
});

it('should move focus to textbox and be inactive if pressed enter on it', () => {
const textarea = element.find('textarea');
sinon.spy(textarea[0], 'focus');
const ev = angular.element.Event('keydown'); // eslint-disable-line new-cap
ev.keyCode = ENTER_KEY;
element.find('.uiAceKeyboardHint').trigger(ev);
expect(textarea[0].focus.called).to.be(true);
expect(element.find('.uiAceKeyboardHint').hasClass('uiAceKeyboardHint-isInactive')).to.be(true);
});

it('should be shown again, when pressing Escape in ace editor', () => {
const textarea = element.find('textarea');
const hint = element.find('.uiAceKeyboardHint');
sinon.spy(hint[0], 'focus');
const ev = angular.element.Event('keydown'); // eslint-disable-line new-cap
ev.keyCode = ESC_KEY_CODE;
textarea.trigger(ev);
expect(hint[0].focus.called).to.be(true);
expect(hint.hasClass('uiAceKeyboardHint-isInactive')).to.be(false);
});
});

describe('ui-ace textarea', () => {
it('should not be tabable anymore', () => {
expect(element.find('textarea').attr('tabindex')).to.be('-1');
});
});

});
12 changes: 9 additions & 3 deletions src/ui/public/accessibility/kbn_ui_ace_keyboard_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { ESC_KEY_CODE, ENTER_KEY } from 'ui_framework/services';

let aceKeyboardModeId = 0;

uiModules.get('kibana').directive('kbnUiAceKeyboardMode', () => ({
restrict: 'A',
link(scope, element) {
uiModules.get('kibana')
.factory('kbnUiAceKeyboardModeService', () => ({
initialize(scope, element) {
const uniqueId = `uiAceKeyboardHint-${scope.$id}-${aceKeyboardModeId++}`;

const hint = angular.element(
Expand Down Expand Up @@ -77,4 +77,10 @@ uiModules.get('kibana').directive('kbnUiAceKeyboardMode', () => ({
uiAceTextbox.attr('tabindex', '-1');
element.prepend(hint);
}
}))
.directive('kbnUiAceKeyboardMode', (kbnUiAceKeyboardModeService) => ({
restrict: 'A',
link(scope, element) {
kbnUiAceKeyboardModeService.initialize(scope, element);
}
}));
15 changes: 13 additions & 2 deletions src/ui/public/styles/bootstrap/dropdowns.less
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
}

// Links within the dropdown menu
> li > a {
> li > a,
> li > button {
display: block;
padding: 3px 20px;
clear: both;
Expand All @@ -71,10 +72,19 @@
color: @dropdown-link-color;
white-space: nowrap; // prevent links from randomly breaking onto new lines
}

> li > button {
appearance: none;
background: none;
border: none;
width: 100%;
text-align: left;
}
}

// Hover/Focus state
.dropdown-menu > li > a {
.dropdown-menu > li > a,
.dropdown-menu > li > button {
&:hover,
&:focus {
text-decoration: none;
Expand All @@ -84,6 +94,7 @@
}

// Active state
.dropdown-menu > .active > button,
.dropdown-menu > .active > a {
&,
&:hover,
Expand Down