Skip to content

Commit 63c7664

Browse files
author
Jens Vannerum
committed
117544: First implementation of an aria friendly disabled state
1 parent 404ccd9 commit 63c7664

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Directive, Input, HostBinding, HostListener } from '@angular/core';
2+
3+
@Directive({
4+
selector: '[dsDisabled]'
5+
})
6+
export class DisabledDirective {
7+
8+
@Input() set dsDisabled(value: boolean) {
9+
this.isDisabled = value;
10+
}
11+
12+
@HostBinding('attr.aria-disabled') isDisabled = false;
13+
@HostBinding('class.disabled') get disabledClass() { return this.isDisabled; }
14+
15+
@HostListener('click', ['$event'])
16+
handleClick(event: Event) {
17+
if (this.isDisabled) {
18+
event.preventDefault();
19+
event.stopImmediatePropagation();
20+
}
21+
}
22+
23+
@HostListener('keydown', ['$event'])
24+
handleKeydown(event: KeyboardEvent) {
25+
if (this.isDisabled && (event.key === 'Enter' || event.key === 'Space')) {
26+
event.preventDefault();
27+
event.stopImmediatePropagation();
28+
}
29+
}
30+
}
31+

src/app/shared/shared.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ import {
284284
} from '../item-page/simple/field-components/specific-field/title/themed-item-page-field.component';
285285
import { BitstreamListItemComponent } from './object-list/bitstream-list-item/bitstream-list-item.component';
286286
import { NgxPaginationModule } from 'ngx-pagination';
287+
import {DisabledDirective} from './disabled-directive';
287288

288289
const MODULES = [
289290
CommonModule,
@@ -491,6 +492,7 @@ const DIRECTIVES = [
491492
MetadataFieldValidator,
492493
HoverClassDirective,
493494
ContextHelpDirective,
495+
DisabledDirective,
494496
];
495497

496498
@NgModule({

src/styles/_global-styles.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,14 @@ ul.dso-edit-menu-dropdown > li .nav-item.nav-link {
267267
.table td {
268268
vertical-align: middle;
269269
}
270+
271+
// An element that is disabled should not have focus styles to avoid confusion
272+
// It however is still focusable for screen readers and keyboard navigation
273+
.disabled {
274+
pointer-events: none;
275+
}
276+
277+
.disabled:focus {
278+
outline: none;
279+
box-shadow: none;
280+
}

0 commit comments

Comments
 (0)