Skip to content

Commit 685e6d8

Browse files
author
Jens Vannerum
committed
117544: PR feedback
- added typedocs - changed directive to only be present for buttons - various other small fixes
1 parent 0945021 commit 685e6d8

21 files changed

Lines changed: 110 additions & 30 deletions

File tree

src/app/admin/admin-reports/filtered-items/filtered-items.component.html

Whitespace-only changes.

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.html

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,53 @@
66
<textarea class="form-control" rows="5" *ngIf="mdValue.editing && !mdRepresentation" [(ngModel)]="mdValue.newValue.value"
77
[attr.aria-label]="(dsoType + '.edit.metadata.edit.value') | translate"
88
[dsDebounce]="300" (onDebounce)="confirm.emit(false)"></textarea>
9+
<ds-dynamic-scrollable-dropdown *ngIf="mdValue.editing && (isScrollableVocabulary() | async)"
10+
[bindId]="mdField"
11+
[group]="group"
12+
[model]="getModel()"
13+
(change)="onChangeAuthorityField($event)">
14+
</ds-dynamic-scrollable-dropdown>
15+
<ds-dynamic-onebox *ngIf="mdValue.editing && ((isHierarchicalVocabulary() | async) || (isSuggesterVocabulary() | async))"
16+
[group]="group"
17+
[model]="getModel()"
18+
(change)="onChangeAuthorityField($event)">
19+
</ds-dynamic-onebox>
20+
<div *ngIf="!isVirtual && !mdValue.editing && mdValue.newValue.authority && mdValue.newValue.confidence !== ConfidenceTypeEnum.CF_UNSET && mdValue.newValue.confidence !== ConfidenceTypeEnum.CF_NOVALUE">
21+
<span class="badge badge-light border" >
22+
<i dsAuthorityConfidenceState
23+
class="fas fa-fw p-0"
24+
aria-hidden="true"
25+
[authorityValue]="mdValue.newValue"
26+
[iconMode]="true"
27+
></i>
28+
{{ dsoType + '.edit.metadata.authority.label' | translate }} {{ mdValue.newValue.authority }}
29+
</span>
30+
</div>
31+
<div class="mt-2" *ngIf=" mdValue.editing && (isAuthorityControlled() | async) && (isSuggesterVocabulary() | async)">
32+
<div class="btn-group w-75">
33+
<i dsAuthorityConfidenceState
34+
class="fas fa-fw p-0 mr-1 mt-auto mb-auto"
35+
aria-hidden="true"
36+
[authorityValue]="mdValue.newValue.confidence"
37+
[iconMode]="true"
38+
></i>
39+
<input class="form-control form-outline" data-test="authority-input" [(ngModel)]="mdValue.newValue.authority" [disabled]="!editingAuthority"
40+
[attr.aria-label]="(dsoType + '.edit.metadata.edit.authority.key') | translate"
41+
(change)="onChangeAuthorityKey()" />
42+
<button class="btn btn-outline-secondary btn-sm ng-star-inserted" id="metadata-confirm-btn" *ngIf="!editingAuthority"
43+
[title]="dsoType + '.edit.metadata.edit.buttons.open-authority-edition' | translate"
44+
ngbTooltip="{{ dsoType + '.edit.metadata.edit.buttons.open-authority-edition' | translate }}"
45+
(click)="onChangeEditingAuthorityStatus(true)">
46+
<i class="fas fa-lock fa-fw"></i>
47+
</button>
48+
<button class="btn btn-outline-success btn-sm ng-star-inserted" id="metadata-confirm-btn" *ngIf="editingAuthority"
49+
[title]="dsoType + '.edit.metadata.edit.buttons.close-authority-edition' | translate"
50+
ngbTooltip="{{ dsoType + '.edit.metadata.edit.buttons.close-authority-edition' | translate }}"
51+
(click)="onChangeEditingAuthorityStatus(false)">
52+
<i class="fas fa-lock-open fa-fw"></i>
53+
</button>
54+
</div>
55+
</div>
956
<div class="d-flex" *ngIf="mdRepresentation">
1057
<a class="mr-2" target="_blank" [routerLink]="mdRepresentationItemRoute$ | async">{{ mdRepresentationName$ | async }}</a>
1158
<ds-themed-type-badge [object]="mdRepresentation"></ds-themed-type-badge>

src/app/item-page/edit-item-page/item-delete/item-delete.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1>{{headerMessage | translate: {id: item.handle} }}</h1>
1818

1919
<div class="m-2" (click)="setSelected(typeDto.relationshipType, !selected)">
2020
<label>
21-
<input type="checkbox" [checked]="selected" [dsDisabled]="isDeleting$ | async">
21+
<input type="checkbox" [checked]="selected" [disabled]="isDeleting$ | async">
2222
</label>
2323
</div>
2424

src/app/shared/access-control-form-container/access-control-array-form/access-control-array-form.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</label>
1414
<select
1515
id="accesscontroloption-{{control.id}}"
16-
[dsDisabled]="ngForm.disabled"
16+
[disabled]="ngForm.disabled"
1717
[(ngModel)]="control.itemName"
1818
(ngModelChange)="accessControlChanged(control, $event)"
1919
name="itemName-{{control.id}}"

src/app/shared/access-control-form-container/access-control-form-container.component.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h2 class="h3 mb-0 mr-4">
3131
<div class="form-check">
3232
<input class="form-check-input" type="radio"
3333
name="itemMode" id="itemReplace" value="replace"
34-
[dsDisabled]="!state.item.toggleStatus"
34+
[disabled]="!state.item.toggleStatus"
3535
[(ngModel)]="state.item.accessMode">
3636
<label class="form-check-label" for="itemReplace">
3737
{{'access-control-replace-all' | translate}}
@@ -40,7 +40,7 @@ <h2 class="h3 mb-0 mr-4">
4040
<div class="form-check">
4141
<input class="form-check-input" type="radio"
4242
name="itemMode" id="itemAdd" value="add"
43-
[dsDisabled]="!state.item.toggleStatus"
43+
[disabled]="!state.item.toggleStatus"
4444
[(ngModel)]="state.item.accessMode">
4545
<label class="form-check-label" for="itemAdd">
4646
{{'access-control-add-to-existing' | translate}}
@@ -85,7 +85,7 @@ <h2 class="h3 mb-0 mr-4">
8585
<div class="form-check">
8686
<input class="form-check-input" type="radio"
8787
name="changesLimit" id="processAll" value="all"
88-
[dsDisabled]="!state.bitstream.toggleStatus"
88+
[disabled]="!state.bitstream.toggleStatus"
8989
[(ngModel)]="state.bitstream.changesLimit">
9090
<label class="form-check-label" for="processAll">
9191
{{'access-control-process-all-bitstreams' | translate}}
@@ -94,7 +94,7 @@ <h2 class="h3 mb-0 mr-4">
9494
<div class="form-check">
9595
<input class="form-check-input mt-2" type="radio"
9696
name="changesLimit" id="processSelected" value="selected"
97-
[dsDisabled]="!state.bitstream.toggleStatus"
97+
[disabled]="!state.bitstream.toggleStatus"
9898
[(ngModel)]="state.bitstream.changesLimit">
9999
<label class="form-check-label" for="processSelected">
100100
{{ state.bitstream.selectedBitstreams.length }}
@@ -123,7 +123,7 @@ <h2 class="h3 mb-0 mr-4">
123123
<div class="form-check">
124124
<input class="form-check-input" type="radio"
125125
name="bitstreamMode" id="bitstreamReplace" value="replace"
126-
[dsDisabled]="!state.bitstream.toggleStatus"
126+
[disabled]="!state.bitstream.toggleStatus"
127127
[(ngModel)]="state.bitstream.accessMode">
128128
<label class="form-check-label" for="bitstreamReplace">
129129
{{'access-control-replace-all' | translate}}
@@ -132,7 +132,7 @@ <h2 class="h3 mb-0 mr-4">
132132
<div class="form-check">
133133
<input class="form-check-input" type="radio"
134134
name="bitstreamMode" id="bitstreamAdd" value="add"
135-
[dsDisabled]="!state.bitstream.toggleStatus"
135+
[disabled]="!state.bitstream.toggleStatus"
136136
[(ngModel)]="state.bitstream.accessMode">
137137
<label class="form-check-label" for="bitstreamAdd">
138138
{{'access-control-add-to-existing' | translate}}

src/app/shared/disabled-directive.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ describe('DisabledDirective', () => {
4040
expect(button.nativeElement.classList.contains('disabled')).toBeTrue();
4141
});
4242

43+
it('should bind aria-disabled to false and not have disabled class when isDisabled is false', () => {
44+
component.isDisabled = false;
45+
fixture.detectChanges();
46+
47+
expect(button.nativeElement.getAttribute('aria-disabled')).toBe('false');
48+
expect(button.nativeElement.classList.contains('disabled')).toBeFalse();
49+
});
50+
4351
it('should prevent click events when disabled', () => {
4452
component.isDisabled = true;
4553
fixture.detectChanges();

src/app/shared/disabled-directive.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,36 @@ import { Directive, Input, HostBinding, HostListener } from '@angular/core';
33
@Directive({
44
selector: '[dsDisabled]'
55
})
6+
7+
/**
8+
* This directive can be added to a html element to disable it (make it non-interactive).
9+
* It acts as a replacement for HTML's disabled attribute.
10+
*
11+
* This directive should always be used instead of the HTML disabled attribute as it is more accessible.
12+
*/
613
export class DisabledDirective {
714

815
@Input() set dsDisabled(value: boolean) {
916
this.isDisabled = !!value;
1017
}
1118

19+
/**
20+
* Binds the aria-disabled attribute to the directive's isDisabled property.
21+
* This is used to make the element accessible to screen readers. If the element is disabled, the screen reader will announce it as such.
22+
*/
1223
@HostBinding('attr.aria-disabled') isDisabled = false;
24+
25+
/**
26+
* Binds the class attribute to the directive's isDisabled property.
27+
* This is used to style the element when it is disabled (make it look disabled).
28+
*/
1329
@HostBinding('class.disabled') get disabledClass() { return this.isDisabled; }
1430

31+
/**
32+
* Prevents the default action and stops the event from propagating when the element is disabled.
33+
* This is used to prevent the element from being interacted with when it is disabled (via mouse click).
34+
* @param event The click event.
35+
*/
1536
@HostListener('click', ['$event'])
1637
handleClick(event: Event) {
1738
if (this.isDisabled) {
@@ -20,7 +41,12 @@ export class DisabledDirective {
2041
}
2142
}
2243

23-
@HostListener('keydown', ['$event'])
44+
/**
45+
* Prevents the default action and stops the event from propagating when the element is disabled.
46+
* This is used to prevent the element from being interacted with when it is disabled (via keystrokes).
47+
* @param event The keydown event.
48+
*/
49+
@HostListener('keydown', ['$event'])
2450
handleKeydown(event: KeyboardEvent) {
2551
if (this.isDisabled && (event.key === 'Enter' || event.key === 'Space')) {
2652
event.preventDefault();

src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<div *ngIf="model.languageCodes && model.languageCodes.length > 0" class="col-xs-2" >
3232
<select
3333
#language="ngModel"
34-
[dsDisabled]="model.readOnly"
34+
[disabled]="model.readOnly"
3535
[(ngModel)]="model.language"
3636
class="form-control"
3737
(blur)="onBlur($event)"

src/app/shared/form/builder/ds-dynamic-form-ui/models/date-picker/date-picker.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ds-number-picker
77
tabindex="0"
88
[id]="model.id + '_year'"
9-
[dsDisabled]="model.disabled"
9+
[disabled]="model.disabled"
1010
[min]="minYear"
1111
[max]="maxYear"
1212
[name]="'year'"
@@ -30,7 +30,7 @@
3030
[(ngModel)]="initialMonth"
3131
[value]="month"
3232
[placeholder]="monthPlaceholder"
33-
[dsDisabled]="!year || model.disabled"
33+
[disabled]="!year || model.disabled"
3434
(blur)="onBlur($event)"
3535
(change)="onChange($event)"
3636
(focus)="onFocus($event)"
@@ -46,7 +46,7 @@
4646
[(ngModel)]="initialDay"
4747
[value]="day"
4848
[placeholder]="dayPlaceholder"
49-
[dsDisabled]="!month || model.disabled"
49+
[disabled]="!month || model.disabled"
5050
(blur)="onBlur($event)"
5151
(change)="onChange($event)"
5252
(focus)="onFocus($event)"

src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[id]="id"
77
[name]="model.name"
88
[value]="modelValuesString"
9-
[dsDisabled]="model.disabled"
9+
[disabled]="model.disabled"
1010
[type]="model.inputType"
1111
[placeholder]="model.placeholder | translate"
1212
[readonly]="model.readOnly">

0 commit comments

Comments
 (0)