Skip to content

Commit

Permalink
Improve accessibility of the Datepicker. (elastic#11753)
Browse files Browse the repository at this point in the history
* Add aria-label and kbn-accessible-click to Local Nav menu buttons.
* Make Share menu keyboard accessible.
* Make datepicker and timepicker keyboard accessible.
* Revert some kbn-accessible-click instances in favor of native button elements.
  • Loading branch information
cjcenizal authored and snide committed May 30, 2017
1 parent 1b4a4dc commit 34eb68c
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 51 deletions.
4 changes: 0 additions & 4 deletions src/ui/public/angular-bootstrap/datepicker/day.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
type="button"
class="kuiDatePickerNavigationButton"
ng-click="move(-1)"
tabindex="-1"
>
<span class="kuiIcon fa-chevron-left"></span>
</button>
Expand All @@ -28,7 +27,6 @@
type="button"
class="kuiDatePickerNavigationButton"
ng-click="toggleMode()"
tabindex="-1"
>
<strong>{{title}}</strong>
</button>
Expand All @@ -37,7 +35,6 @@
type="button"
class="kuiDatePickerNavigationButton"
ng-click="move(1)"
tabindex="-1"
>
<span class="kuiIcon fa-chevron-right"></span>
</button>
Expand Down Expand Up @@ -74,7 +71,6 @@
ng-class="{'kuiDatePickerRowCellContent-isSelected': dt.selected, 'kuiDatePickerRowCellContent-isCurrent': dt.current, 'kuiDatePickerRowCellContent-isOtherMonth': dt.secondary}"
ng-click="select(dt.date)"
ng-disabled="dt.disabled"
tabindex="-1"
>
<span>{{dt.label}}</span>
</button>
Expand Down
4 changes: 0 additions & 4 deletions src/ui/public/angular-bootstrap/datepicker/month.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
type="button"
class="kuiDatePickerNavigationButton"
ng-click="move(-1)"
tabindex="-1"
>
<span class="kuiIcon fa-chevron-left"></span>
</button>
Expand All @@ -28,7 +27,6 @@
type="button"
class="kuiDatePickerNavigationButton"
ng-click="toggleMode()"
tabindex="-1"
>
<strong>{{title}}</strong>
</button>
Expand All @@ -37,7 +35,6 @@
type="button"
class="kuiDatePickerNavigationButton"
ng-click="move(1)"
tabindex="-1"
>
<span class="kuiIcon fa-chevron-right"></span>
</button>
Expand All @@ -61,7 +58,6 @@
ng-class="{'kuiDatePickerRowCellContent-isSelected': dt.selected, 'kuiDatePickerRowCellContent-isCurrent': dt.current}"
ng-click="select(dt.date)"
ng-disabled="dt.disabled"
tabindex="-1"
>
<span>{{dt.label}}</span>
</button>
Expand Down
4 changes: 0 additions & 4 deletions src/ui/public/angular-bootstrap/datepicker/year.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
type="button"
class="kuiDatePickerNavigationButton"
ng-click="move(-1)"
tabindex="-1"
>
<span class="kuiIcon fa-chevron-left"></span>
</button>
Expand All @@ -28,7 +27,6 @@
type="button"
class="kuiDatePickerNavigationButton"
ng-click="toggleMode()"
tabindex="-1"
>
<strong>{{title}}</strong>
</button>
Expand All @@ -37,7 +35,6 @@
type="button"
class="kuiDatePickerNavigationButton"
ng-click="move(1)"
tabindex="-1"
>
<span class="kuiIcon fa-chevron-right"></span>
</button>
Expand All @@ -61,7 +58,6 @@
ng-class="{'kuiDatePickerRowCellContent-isSelected': dt.selected, 'kuiDatePickerRowCellContent-isCurrent': dt.current}"
ng-click="select(dt.date)"
ng-disabled="dt.disabled"
tabindex="-1"
>
<span>{{dt.label}}</span>
</button>
Expand Down
11 changes: 8 additions & 3 deletions src/ui/public/directives/pretty_duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ module.directive('prettyDuration', function (config, quickRanges, timeUnits) {
lookupByRange[frame.from + ' to ' + frame.to] = frame;
});

function setText(text) {
$elem.text(text);
$elem.attr('aria-label', `Current time range is ${text}`);
}

function stringify() {
let text;
// If both parts are date math, try to look up a reasonable string
if ($scope.from && $scope.to && !moment.isMoment($scope.from) && !moment.isMoment($scope.to)) {
const tryLookup = lookupByRange[$scope.from.toString() + ' to ' + $scope.to.toString()];
if (tryLookup) {
$elem.text(tryLookup.display);
setText(tryLookup.display);
} else {
const fromParts = $scope.from.toString().split('-');
if ($scope.to.toString() === 'now' && fromParts[0] === 'now' && fromParts[1]) {
Expand All @@ -37,7 +42,7 @@ module.directive('prettyDuration', function (config, quickRanges, timeUnits) {
if (rounded[1]) {
text = text + ' rounded to the ' + timeUnits[rounded[1]];
}
$elem.text(text);
setText(text);
} else {
cantLookup();
}
Expand All @@ -62,7 +67,7 @@ module.directive('prettyDuration', function (config, quickRanges, timeUnits) {
}
}
});
$elem.text(display.from + ' to ' + display.to);
setText(`${display.from} to ${display.to}`);
}

$scope.$watch('from', stringify);
Expand Down
7 changes: 3 additions & 4 deletions src/ui/public/kbn_top_nav/kbn_top_nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<!-- Right-side: menu -->
<div class="kuiLocalNavRow__section">
<div class="kuiLocalMenu">
<div
<button
class="kuiLocalMenuItem"
ng-repeat="menuItem in kbnTopNav.menuItems"
aria-label="{{::menuItem.description}}"
Expand All @@ -28,8 +28,7 @@
tooltip-popup-delay="400"
tooltip-append-to-body="1"
data-test-subj="{{menuItem.testId}}"
>
</div>
></button>

<!-- Time-picker "menu item" -->
<kbn-global-timepicker></kbn-global-timepicker>
Expand All @@ -43,7 +42,7 @@
ng-show="kbnTopNav.rendered"
>
<button class="kuiLocalDropdownCloseButton" ng-click="kbnTopNav.close()">
<span class="fa fa-chevron-circle-up"></span>
<span class="kuiIcon fa-chevron-circle-up"></span>
</button>
<div id="template_wrapper">
<!-- Content gets dynamically inserted here. -->
Expand Down
8 changes: 8 additions & 0 deletions src/ui/public/share/views/share.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<a
class="kuiLocalDropdownHeader__action"
ng-click="share.copyToClipboard('#originalIframeUrl')"
kbn-accessible-click
>
Copy
</a>
Expand Down Expand Up @@ -62,6 +63,7 @@
<a
class="kuiLocalDropdownHeader__action"
ng-click="share.copyToClipboard('#originalUrl')"
kbn-accessible-click
>
Copy
</a>
Expand Down Expand Up @@ -104,6 +106,7 @@
class="kuiLocalDropdownHeader__action"
ng-if="!share.urlFlags.shortSnapshotIframe"
ng-click="share.toggleShortSnapshotIframeUrl()"
kbn-accessible-click
>
Short URL
</a>
Expand All @@ -112,13 +115,15 @@
class="kuiLocalDropdownHeader__action"
ng-if="share.urlFlags.shortSnapshotIframe"
ng-click="share.toggleShortSnapshotIframeUrl()"
kbn-accessible-click
>
Long URL
</a>

<a
class="kuiLocalDropdownHeader__action"
ng-click="share.copyToClipboard('#snapshotIframeUrl')"
kbn-accessible-click
>
Copy
</a>
Expand Down Expand Up @@ -153,6 +158,7 @@
class="kuiLocalDropdownHeader__action"
ng-if="!share.urlFlags.shortSnapshot"
ng-click="share.toggleShortSnapshotUrl()"
kbn-accessible-click
>
Short URL
</a>
Expand All @@ -161,6 +167,7 @@
class="kuiLocalDropdownHeader__action"
ng-if="share.urlFlags.shortSnapshot"
ng-click="share.toggleShortSnapshotUrl()"
kbn-accessible-click
>
Long URL
</a>
Expand All @@ -169,6 +176,7 @@
data-test-subj="sharedSnapshotCopyButton"
class="kuiLocalDropdownHeader__action"
ng-click="share.copyToClipboard('#snapshotUrl')"
kbn-accessible-click
>
Copy
</a>
Expand Down
64 changes: 45 additions & 19 deletions src/ui/public/timepicker/kbn_global_timepicker.html
Original file line number Diff line number Diff line change
@@ -1,46 +1,72 @@
<div ng-show="timefilter.enabled" data-shared-timefilter="{{timefilter.enabled}}" class="kuiLocalMenu" data-test-subj="globalTimepicker">
<div
<button
class="kuiLocalMenuItem"
aria-label="{{ timefilter.refreshInterval.pause ? 'Resume refreshing data' : 'Pause refreshing data' }}"
ng-click="toggleRefresh()"
ng-show="timefilter.refreshInterval.value > 0"
>
<span class="fa" ng-class="timefilter.refreshInterval.pause ? 'fa-play' : 'fa-pause'"></span>
</div>
<span
class="kuiIcon"
aria-hidden="true"
ng-class="timefilter.refreshInterval.pause ? 'fa-play' : 'fa-pause'"
></span>
</button>

<div
<button
class="kuiLocalMenuItem navbar-timepicker-auto-refresh-desc"
ng-class="{'kuiLocalMenuItem-isSelected': kbnTopNav.isCurrent('interval') }"
ng-show="timefilter.refreshInterval.value > 0 || kbnTopNav.isCurrent('interval') || kbnTopNav.isCurrent('filter')"
ng-click="kbnTopNav.toggle('interval')"
>
<span ng-show="timefilter.refreshInterval.value === 0">
<span class="fa fa-repeat"></span> Auto-refresh
<span aria-hidden="true" class="kuiIcon fa-repeat"></span> Auto-refresh
</span>
<span ng-show="timefilter.refreshInterval.value > 0">
{{timefilter.refreshInterval.display}}

<span
ng-show="timefilter.refreshInterval.value > 0"
aria-label="{{ 'Data will refresh every ' + timefilter.refreshInterval.display }}"
>
{{ timefilter.refreshInterval.display }}
</span>
</div>
</button>

<div class="kuiLocalMenuItem" ng-click="back()">
<span class="fa fa-chevron-left ng-scope" tooltip="Move backward in time"></span>
</div>
<button
class="kuiLocalMenuItem"
ng-click="back()"
aria-label="Move backward in time"
>
<span
class="kuiIcon fa-chevron-left"
aria-hidden="true"
tooltip="Move backward in time"
></span>
</button>

<div
<button
data-test-subj="globalTimepickerButton"
class="kuiLocalMenuItem navbar-timepicker-time-desc"
ng-class="{'kuiLocalMenuItem-isSelected': kbnTopNav.isCurrent('filter')}"
ng-click="kbnTopNav.toggle('filter')"
aria-label="Open time range picker"
aria-haspopup="true"
aria-expanded="false"
>
<span aria-hidden="true" class="fa fa-clock-o"></span>
<span aria-hidden="true" class="kuiIcon fa-clock-o"></span>
<pretty-duration
from="timefilter.time.from" to="timefilter.time.to"
from="timefilter.time.from"
to="timefilter.time.to"
data-test-subj="globalTimepickerRange"
></pretty-duration>
</div>
</button>

<div class="kuiLocalMenuItem" ng-click="forward()">
<span class="fa fa-chevron-right ng-scope" tooltip="Move forward in time"></span>
</div>
<button
class="kuiLocalMenuItem"
ng-click="forward()"
aria-label="Move forward in time"
>
<span
aria-hidden="true"
class="kuiIcon fa-chevron-right"
tooltip="Move forward in time"
></span>
</button>
</div>
Loading

0 comments on commit 34eb68c

Please sign in to comment.