117544: PR feedback

- added typedocs
- changed directive to only be present for buttons
- various other small fixes
This commit is contained in:
Jens Vannerum
2024-09-16 13:44:06 +02:00
parent 0945021378
commit 685e6d83c5
21 changed files with 110 additions and 30 deletions

View File

@@ -6,6 +6,53 @@
<textarea class="form-control" rows="5" *ngIf="mdValue.editing && !mdRepresentation" [(ngModel)]="mdValue.newValue.value"
[attr.aria-label]="(dsoType + '.edit.metadata.edit.value') | translate"
[dsDebounce]="300" (onDebounce)="confirm.emit(false)"></textarea>
<ds-dynamic-scrollable-dropdown *ngIf="mdValue.editing && (isScrollableVocabulary() | async)"
[bindId]="mdField"
[group]="group"
[model]="getModel()"
(change)="onChangeAuthorityField($event)">
</ds-dynamic-scrollable-dropdown>
<ds-dynamic-onebox *ngIf="mdValue.editing && ((isHierarchicalVocabulary() | async) || (isSuggesterVocabulary() | async))"
[group]="group"
[model]="getModel()"
(change)="onChangeAuthorityField($event)">
</ds-dynamic-onebox>
<div *ngIf="!isVirtual && !mdValue.editing && mdValue.newValue.authority && mdValue.newValue.confidence !== ConfidenceTypeEnum.CF_UNSET && mdValue.newValue.confidence !== ConfidenceTypeEnum.CF_NOVALUE">
<span class="badge badge-light border" >
<i dsAuthorityConfidenceState
class="fas fa-fw p-0"
aria-hidden="true"
[authorityValue]="mdValue.newValue"
[iconMode]="true"
></i>
{{ dsoType + '.edit.metadata.authority.label' | translate }} {{ mdValue.newValue.authority }}
</span>
</div>
<div class="mt-2" *ngIf=" mdValue.editing && (isAuthorityControlled() | async) && (isSuggesterVocabulary() | async)">
<div class="btn-group w-75">
<i dsAuthorityConfidenceState
class="fas fa-fw p-0 mr-1 mt-auto mb-auto"
aria-hidden="true"
[authorityValue]="mdValue.newValue.confidence"
[iconMode]="true"
></i>
<input class="form-control form-outline" data-test="authority-input" [(ngModel)]="mdValue.newValue.authority" [disabled]="!editingAuthority"
[attr.aria-label]="(dsoType + '.edit.metadata.edit.authority.key') | translate"
(change)="onChangeAuthorityKey()" />
<button class="btn btn-outline-secondary btn-sm ng-star-inserted" id="metadata-confirm-btn" *ngIf="!editingAuthority"
[title]="dsoType + '.edit.metadata.edit.buttons.open-authority-edition' | translate"
ngbTooltip="{{ dsoType + '.edit.metadata.edit.buttons.open-authority-edition' | translate }}"
(click)="onChangeEditingAuthorityStatus(true)">
<i class="fas fa-lock fa-fw"></i>
</button>
<button class="btn btn-outline-success btn-sm ng-star-inserted" id="metadata-confirm-btn" *ngIf="editingAuthority"
[title]="dsoType + '.edit.metadata.edit.buttons.close-authority-edition' | translate"
ngbTooltip="{{ dsoType + '.edit.metadata.edit.buttons.close-authority-edition' | translate }}"
(click)="onChangeEditingAuthorityStatus(false)">
<i class="fas fa-lock-open fa-fw"></i>
</button>
</div>
</div>
<div class="d-flex" *ngIf="mdRepresentation">
<a class="mr-2" target="_blank" [routerLink]="mdRepresentationItemRoute$ | async">{{ mdRepresentationName$ | async }}</a>
<ds-themed-type-badge [object]="mdRepresentation"></ds-themed-type-badge>

View File

@@ -18,7 +18,7 @@
<div class="m-2" (click)="setSelected(typeDto.relationshipType, !selected)">
<label>
<input type="checkbox" [checked]="selected" [dsDisabled]="isDeleting$ | async">
<input type="checkbox" [checked]="selected" [disabled]="isDeleting$ | async">
</label>
</div>

View File

@@ -13,7 +13,7 @@
</label>
<select
id="accesscontroloption-{{control.id}}"
[dsDisabled]="ngForm.disabled"
[disabled]="ngForm.disabled"
[(ngModel)]="control.itemName"
(ngModelChange)="accessControlChanged(control, $event)"
name="itemName-{{control.id}}"

View File

@@ -31,7 +31,7 @@
<div class="form-check">
<input class="form-check-input" type="radio"
name="itemMode" id="itemReplace" value="replace"
[dsDisabled]="!state.item.toggleStatus"
[disabled]="!state.item.toggleStatus"
[(ngModel)]="state.item.accessMode">
<label class="form-check-label" for="itemReplace">
{{'access-control-replace-all' | translate}}
@@ -40,7 +40,7 @@
<div class="form-check">
<input class="form-check-input" type="radio"
name="itemMode" id="itemAdd" value="add"
[dsDisabled]="!state.item.toggleStatus"
[disabled]="!state.item.toggleStatus"
[(ngModel)]="state.item.accessMode">
<label class="form-check-label" for="itemAdd">
{{'access-control-add-to-existing' | translate}}
@@ -85,7 +85,7 @@
<div class="form-check">
<input class="form-check-input" type="radio"
name="changesLimit" id="processAll" value="all"
[dsDisabled]="!state.bitstream.toggleStatus"
[disabled]="!state.bitstream.toggleStatus"
[(ngModel)]="state.bitstream.changesLimit">
<label class="form-check-label" for="processAll">
{{'access-control-process-all-bitstreams' | translate}}
@@ -94,7 +94,7 @@
<div class="form-check">
<input class="form-check-input mt-2" type="radio"
name="changesLimit" id="processSelected" value="selected"
[dsDisabled]="!state.bitstream.toggleStatus"
[disabled]="!state.bitstream.toggleStatus"
[(ngModel)]="state.bitstream.changesLimit">
<label class="form-check-label" for="processSelected">
{{ state.bitstream.selectedBitstreams.length }}
@@ -123,7 +123,7 @@
<div class="form-check">
<input class="form-check-input" type="radio"
name="bitstreamMode" id="bitstreamReplace" value="replace"
[dsDisabled]="!state.bitstream.toggleStatus"
[disabled]="!state.bitstream.toggleStatus"
[(ngModel)]="state.bitstream.accessMode">
<label class="form-check-label" for="bitstreamReplace">
{{'access-control-replace-all' | translate}}
@@ -132,7 +132,7 @@
<div class="form-check">
<input class="form-check-input" type="radio"
name="bitstreamMode" id="bitstreamAdd" value="add"
[dsDisabled]="!state.bitstream.toggleStatus"
[disabled]="!state.bitstream.toggleStatus"
[(ngModel)]="state.bitstream.accessMode">
<label class="form-check-label" for="bitstreamAdd">
{{'access-control-add-to-existing' | translate}}

View File

@@ -40,6 +40,14 @@ describe('DisabledDirective', () => {
expect(button.nativeElement.classList.contains('disabled')).toBeTrue();
});
it('should bind aria-disabled to false and not have disabled class when isDisabled is false', () => {
component.isDisabled = false;
fixture.detectChanges();
expect(button.nativeElement.getAttribute('aria-disabled')).toBe('false');
expect(button.nativeElement.classList.contains('disabled')).toBeFalse();
});
it('should prevent click events when disabled', () => {
component.isDisabled = true;
fixture.detectChanges();

View File

@@ -3,15 +3,36 @@ import { Directive, Input, HostBinding, HostListener } from '@angular/core';
@Directive({
selector: '[dsDisabled]'
})
/**
* This directive can be added to a html element to disable it (make it non-interactive).
* It acts as a replacement for HTML's disabled attribute.
*
* This directive should always be used instead of the HTML disabled attribute as it is more accessible.
*/
export class DisabledDirective {
@Input() set dsDisabled(value: boolean) {
this.isDisabled = !!value;
}
/**
* Binds the aria-disabled attribute to the directive's isDisabled property.
* This is used to make the element accessible to screen readers. If the element is disabled, the screen reader will announce it as such.
*/
@HostBinding('attr.aria-disabled') isDisabled = false;
/**
* Binds the class attribute to the directive's isDisabled property.
* This is used to style the element when it is disabled (make it look disabled).
*/
@HostBinding('class.disabled') get disabledClass() { return this.isDisabled; }
/**
* Prevents the default action and stops the event from propagating when the element is disabled.
* This is used to prevent the element from being interacted with when it is disabled (via mouse click).
* @param event The click event.
*/
@HostListener('click', ['$event'])
handleClick(event: Event) {
if (this.isDisabled) {
@@ -20,7 +41,12 @@ export class DisabledDirective {
}
}
@HostListener('keydown', ['$event'])
/**
* Prevents the default action and stops the event from propagating when the element is disabled.
* This is used to prevent the element from being interacted with when it is disabled (via keystrokes).
* @param event The keydown event.
*/
@HostListener('keydown', ['$event'])
handleKeydown(event: KeyboardEvent) {
if (this.isDisabled && (event.key === 'Enter' || event.key === 'Space')) {
event.preventDefault();

View File

@@ -31,7 +31,7 @@
<div *ngIf="model.languageCodes && model.languageCodes.length > 0" class="col-xs-2" >
<select
#language="ngModel"
[dsDisabled]="model.readOnly"
[disabled]="model.readOnly"
[(ngModel)]="model.language"
class="form-control"
(blur)="onBlur($event)"

View File

@@ -6,7 +6,7 @@
<ds-number-picker
tabindex="0"
[id]="model.id + '_year'"
[dsDisabled]="model.disabled"
[disabled]="model.disabled"
[min]="minYear"
[max]="maxYear"
[name]="'year'"
@@ -30,7 +30,7 @@
[(ngModel)]="initialMonth"
[value]="month"
[placeholder]="monthPlaceholder"
[dsDisabled]="!year || model.disabled"
[disabled]="!year || model.disabled"
(blur)="onBlur($event)"
(change)="onChange($event)"
(focus)="onFocus($event)"
@@ -46,7 +46,7 @@
[(ngModel)]="initialDay"
[value]="day"
[placeholder]="dayPlaceholder"
[dsDisabled]="!month || model.disabled"
[disabled]="!month || model.disabled"
(blur)="onBlur($event)"
(change)="onChange($event)"
(focus)="onFocus($event)"

View File

@@ -6,7 +6,7 @@
[id]="id"
[name]="model.name"
[value]="modelValuesString"
[dsDisabled]="model.disabled"
[disabled]="model.disabled"
[type]="model.inputType"
[placeholder]="model.placeholder | translate"
[readonly]="model.readOnly">

View File

@@ -63,7 +63,7 @@ describe('DsDynamicDisabledComponent', () => {
expect(comp).toBeTruthy();
});
xit('should have a disabled input', () => {
it('should have a disabled input', () => {
const input = de.query(By.css('input'));
expect(input.nativeElement.getAttribute('disabled')).toEqual('');
});

View File

@@ -18,7 +18,7 @@
[name]="model.name"
[type]="model.inputType"
[(ngModel)]="firstInputValue"
[dsDisabled]="isInputDisabled()"
[disabled]="isInputDisabled()"
[placeholder]="model.placeholder | translate"
[readonly]="model.readOnly"
(change)="onChange($event)"
@@ -38,7 +38,7 @@
[name]="model.name + '_2'"
[type]="model.inputType"
[(ngModel)]="secondInputValue"
[dsDisabled]="firstInputValue.length === 0 || isInputDisabled()"
[disabled]="firstInputValue.length === 0 || isInputDisabled()"
[placeholder]="model.secondPlaceholder | translate"
[readonly]="model.readOnly"
(change)="onChange($event)"

View File

@@ -39,7 +39,7 @@
[ngbTypeahead]="search"
[placeholder]="model.placeholder"
[readonly]="model.readOnly"
[dsDisabled]="model.readOnly"
[disabled]="model.readOnly"
[resultTemplate]="rt"
[type]="model.inputType"
[(ngModel)]="currentValue"
@@ -64,7 +64,7 @@
[name]="model.name"
[placeholder]="model.placeholder"
[readonly]="true"
[dsDisabled]="model.readOnly"
[disabled]="model.readOnly"
[type]="model.inputType"
[value]="currentValue?.display"
(focus)="onFocus($event)"

View File

@@ -18,7 +18,7 @@
[id]="id"
[name]="model.name"
[readonly]="true"
[dsDisabled]="model.readOnly"
[disabled]="model.readOnly"
[type]="model.inputType"
[value]="(currentValue | async)"
(blur)="onBlur($event)"

View File

@@ -21,7 +21,7 @@
(change)="update($event); $event.stopPropagation();"
(focus)="onFocus($event); $event.stopPropagation();"
[readonly]="disabled"
[dsDisabled]="disabled"
[disabled]="disabled"
[ngClass]="{'is-invalid': invalid}"
title="{{placeholder}}"
[attr.aria-label]="placeholder"

View File

@@ -36,7 +36,7 @@
container="body"
>
<input class="mr-2" type="checkbox"
[dsDisabled]="!node.item?.selectable"
[disabled]="!node.item?.selectable"
[(ngModel)]="node.isSelected"
[checked]="node.isSelected"
(change)="onSelect(node.item)"
@@ -68,7 +68,7 @@
[openDelay]="500"
container="body">
<input class="mr-2" type="checkbox"
[dsDisabled]="!node.item?.selectable"
[disabled]="!node.item?.selectable"
[(ngModel)]="node.isSelected"
[checked]="node.isSelected"
(change)="onSelect(node.item)"

View File

@@ -16,7 +16,7 @@
</thead>
<tbody>
<tr *ngFor="let selectCollection of selectCollections$ | async">
<td><input #selectCollectionBtn [attr.aria-label]="(selectCollectionBtn.checked ? 'collection.select.table.deselect' : 'collection.select.table.select') | translate" [dsDisabled]="(selectCollection.canSelect$ | async) === false" class="collection-checkbox" [ngModel]="selectCollection.selected$ | async" (change)="switch(selectCollection.dso.id)" type="checkbox" name="{{selectCollection.dso.id}}"></td>
<td><input #selectCollectionBtn [attr.aria-label]="(selectCollectionBtn.checked ? 'collection.select.table.deselect' : 'collection.select.table.select') | translate" [disabled]="(selectCollection.canSelect$ | async) === false" class="collection-checkbox" [ngModel]="selectCollection.selected$ | async" (change)="switch(selectCollection.dso.id)" type="checkbox" name="{{selectCollection.dso.id}}"></td>
<td><a [routerLink]="selectCollection.route">{{ dsoNameService.getName(selectCollection.dso) }}</a></td>
</tr>
</tbody>

View File

@@ -18,7 +18,7 @@
</thead>
<tbody>
<tr *ngFor="let selectItem of selectItems$ | async">
<td><input #selectItemBtn [attr.aria-label]="(selectItemBtn.checked ? 'item.select.table.deselect' : 'item.select.table.select') | translate" [dsDisabled]="(selectItem.canSelect$ | async) === false" class="item-checkbox" [ngModel]="selectItem.selected$ | async" (change)="switch(selectItem.dso.id)" type="checkbox" name="{{selectItem.dso.id}}"></td>
<td><input #selectItemBtn [attr.aria-label]="(selectItemBtn.checked ? 'item.select.table.deselect' : 'item.select.table.select') | translate" [disabled]="(selectItem.canSelect$ | async) === false" class="item-checkbox" [ngModel]="selectItem.selected$ | async" (change)="switch(selectItem.dso.id)" type="checkbox" name="{{selectItem.dso.id}}"></td>
<td *ngIf="!hideCollection">
<span *ngVar="(selectItem.dso.owningCollection | async)?.payload as collection">
<a *ngIf="collection" [routerLink]="['/collections', collection?.id]">

View File

@@ -194,8 +194,7 @@ describe('ItemSelectComponent', () => {
const checkbox = fixture.debugElement.query(By.css('input.item-checkbox')).nativeElement;
expect(authorizationDataService.isAuthorized).toHaveBeenCalled();
expect(checkbox.getAttribute('aria-disabled')).toBe('true');
expect(checkbox.classList.contains('disabled')).toBe(true);
expect(checkbox.disabled).toBeTrue();
}));
});
});

View File

@@ -41,7 +41,7 @@
<div *ngIf="showPaginator" class="pagination justify-content-center clearfix bottom">
<ngb-pagination [boundaryLinks]="paginationOptions.boundaryLinks"
[collectionSize]="collectionSize"
[dsDisabled]="paginationOptions.disabled"
[disabled]="paginationOptions.disabled"
[ellipses]="paginationOptions.ellipses"
[maxSize]="(isXs)?5:paginationOptions.maxSize"
[page]="(currentPage$|async)"

View File

@@ -1,6 +1,6 @@
<div class="mb-4 ccLicense-select">
<ds-select
[dsDisabled]="!submissionCcLicenses">
[disabled]="!submissionCcLicenses">
<ng-container class="selection">
<span *ngIf="!submissionCcLicenses">
@@ -81,7 +81,7 @@
</ng-template>
<ds-select *ngIf="field.enums?.length > 5" [dsDisabled]="field.id === 'jurisdiction' && defaultJurisdiction !== undefined && defaultJurisdiction !== 'none'">
<ds-select *ngIf="field.enums?.length > 5" [disabled]="field.id === 'jurisdiction' && defaultJurisdiction !== undefined && defaultJurisdiction !== 'none'">
<ng-container class="selection" *ngVar="getSelectedOption(getSelectedCcLicense(), field) as option">
<span *ngIf="option">
{{ option.label }}