Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
fix(filter-field): Multiselect keyboard interaction not working corre…
Browse files Browse the repository at this point in the history
…ctly
  • Loading branch information
tonidalmases authored and tomheller committed Jul 5, 2021
1 parent 4c34219 commit f599832
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ test('should choose a multiselect node with the keyboard and submit the correct
await testController
// Select the multiselect node
.pressKey('down down down enter')
// Wait for a certain amout fo time to let the filterfield refresh
// Wait for a certain amount of time to let the filterfield refresh
.wait(250)
// Select the desired option
.pressKey('down space enter')
// Wait for a certain amout fo time to let the filterfield refresh
// Wait for a certain amount of time to let the filterfield refresh
.wait(250);

const tags = await getFilterfieldTags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ import { DtFilterFieldMultiSelect } from './filter-field-multi-select';
})
export class DtFilterFieldMultiSelectTrigger<T>
extends DtFilterFieldElementTrigger<DtFilterFieldMultiSelect<T>>
implements OnDestroy {
implements OnDestroy
{
/** The filter-field multiSelect panel to be attached to this trigger. */
@Input('dtFilterFieldMultiSelect')
get element(): DtFilterFieldMultiSelect<T> {
Expand Down Expand Up @@ -106,7 +107,6 @@ export class DtFilterFieldMultiSelectTrigger<T>
openPanel(): void {
if (!this.element._isOpen) {
super.openPanel();
this._element.focus();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export class DtFilterFieldMultiSelectSubmittedEvent<T> {
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DtFilterFieldMultiSelect<T>
implements DtFilterFieldElement<T>, AfterViewInit {
implements DtFilterFieldElement<T>, AfterViewInit
{
/**
* Whether the first option should be highlighted when the multi-select panel is opened.
* Can be configured globally through the `DT_MULTI_SELECT_DEFAULT_OPTIONS` token.
Expand Down Expand Up @@ -190,9 +191,11 @@ export class DtFilterFieldMultiSelect<T>
takeUntil(this._destroy$),
)
.subscribe((option) => {
this._ngZone?.run(() => {
this._keyManager.setActiveItem(option);
});
if (!option.disabled) {
this._ngZone?.run(() => {
this._keyManager.setActiveItem(option);
});
}
});
}

Expand Down Expand Up @@ -330,6 +333,9 @@ export class DtFilterFieldMultiSelect<T>
}

focus(): void {
this._keyManager.setActiveItem(this._options.first);
const firstOption = this._options.find((option) => !option.disabled);
if (firstOption) {
this._keyManager.setActiveItem(firstOption);
}
}
}
20 changes: 13 additions & 7 deletions libs/barista-components/filter-field/src/filter-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import {
useAnimation,
} from '@angular/animations';
import { FocusMonitor } from '@angular/cdk/a11y';
import { coerceBooleanProperty, BooleanInput } from '@angular/cdk/coercion';
import { BooleanInput, coerceBooleanProperty } from '@angular/cdk/coercion';
import {
BACKSPACE,
DELETE,
ENTER,
ESCAPE,
LEFT_ARROW,
SPACE,
UP_ARROW,
} from '@angular/cdk/keycodes';
import { DOCUMENT } from '@angular/common';
Expand Down Expand Up @@ -59,12 +60,12 @@ import {
DtAutocompleteTrigger,
} from '@dynatrace/barista-components/autocomplete';
import {
_readKeyCode,
CanDisable,
DT_ERROR_ENTER_ANIMATION,
DT_ERROR_ENTER_DELAYED_ANIMATION,
ErrorStateMatcher,
isDefined,
_readKeyCode,
} from '@dynatrace/barista-components/core';
import {
fromEvent,
Expand Down Expand Up @@ -129,6 +130,7 @@ import {
} from './filter-field-util';
import { DtFilterFieldControl } from './filter-field-validation';
import {
_getSourcesOfDtFilterValues,
DefaultSearchOption,
DtAutocompleteValue,
DtFilterFieldTagData,
Expand All @@ -151,7 +153,6 @@ import {
isDtRangeDef,
isDtRangeValue,
isPartialDtOptionDef,
_getSourcesOfDtFilterValues,
} from './types';

// tslint:disable:no-any
Expand Down Expand Up @@ -207,7 +208,8 @@ let currentlyOpenFilterField: DtFilterField<any> | null = null;
],
})
export class DtFilterField<T = any>
implements CanDisable, OnInit, AfterViewInit, OnDestroy, OnChanges {
implements CanDisable, OnInit, AfterViewInit, OnDestroy, OnChanges
{
/** Label for the filter field (e.g. "Filter by"). Will be placed next to the filter icon. */
@Input() label = '';

Expand Down Expand Up @@ -610,6 +612,7 @@ export class DtFilterField<T = any>
return;
} else if (isDtMultiSelectDef(this._currentDef)) {
this._multiSelectTrigger.openPanel();
this._multiSelectTrigger.element.focus();
}
// It is necessary to restore the focus back to the input field
// so the user can directly continue creating more filter nodes.
Expand Down Expand Up @@ -826,6 +829,8 @@ export class DtFilterField<T = any>
}
} else if (keyCode === ESCAPE || (keyCode === UP_ARROW && event.altKey)) {
this._closeFilterPanels();
} else if (isDtMultiSelectDef(this._currentDef) && keyCode === SPACE) {
event.preventDefault();
} else {
if (this._inputFieldKeyboardLocked) {
return;
Expand Down Expand Up @@ -1107,7 +1112,8 @@ export class DtFilterField<T = any>
const recentRangeValue = removed[0];
if (isDtRangeValue(recentRangeValue) && this._currentDef.range) {
// Needed to set this in typescript, because template binding of input would be evaluated to late.
this._filterfieldRange.enabledOperators = this._currentDef.range.operatorFlags;
this._filterfieldRange.enabledOperators =
this._currentDef.range.operatorFlags;
this._filterfieldRange._setValues(recentRangeValue.range);
this._filterfieldRange._setOperator(
recentRangeValue.operator as DtFilterFieldRangeOperator,
Expand Down Expand Up @@ -1545,7 +1551,7 @@ export class DtFilterField<T = any>
return observableOf();
}

return (merge(
return merge(
fromEvent<MouseEvent>(this._document, 'click'),
fromEvent<TouchEvent>(this._document, 'touchend'),
).pipe(
Expand All @@ -1558,7 +1564,7 @@ export class DtFilterField<T = any>
(!filterField || !filterField.contains(clickTarget))
);
}),
) as any) as Observable<void>;
) as any as Observable<void>;
}

/**
Expand Down

0 comments on commit f599832

Please sign in to comment.