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): Fixes an issue where the user can interact while i…
Browse files Browse the repository at this point in the history
…n loading state.

Fixes #1464
  • Loading branch information
thomaspink committed Aug 28, 2020
1 parent f98469a commit 7b593b7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions libs/barista-components/filter-field/src/filter-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#input
type="text"
class="dt-filter-field-input"
[readonly]="loading"
[attr.aria-label]="ariaLabel"
[dtAutocomplete]="autocomplete"
[dtAutocompleteDisabled]="!_autocompleteOptionsOrGroups.length || loading"
Expand Down
42 changes: 42 additions & 0 deletions libs/barista-components/filter-field/src/filter-field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,48 @@ describe('DtFilterField', () => {
expect(options[0].textContent).toContain('Upper Austria');
expect(options[1].textContent).toContain('Vienna');
});

it('should mark the input as readonly while loading async data', () => {
const DATA = {
autocomplete: [
{
name: 'AUT',
async: true,
autocomplete: [],
},
],
};
const ASYNC_DATA = {
name: 'AUT',
autocomplete: [
{
name: 'Linz',
},
],
};

const input = getInput(fixture);

fixture.componentInstance.dataSource.data = DATA;
fixture.detectChanges();
filterField.focus();
advanceFilterfieldCycle();

// No readonly attribute should be present at the beginning.
expect(input.readOnly).toBeFalsy();

getAndClickOption(overlayContainerElement, 0);

// readonly should be added while waiting for the data to be loaded
expect(input.readOnly).toBeTruthy();

fixture.componentInstance.dataSource.data = ASYNC_DATA;
fixture.detectChanges();
advanceFilterfieldCycle(true, true);

// readonly should be removed after the async data is loaded
expect(input.readOnly).toBeFalsy();
});
});

describe('with range option', () => {
Expand Down
8 changes: 8 additions & 0 deletions libs/barista-components/filter-field/src/filter-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,10 @@ export class DtFilterField<T = any>

/** @internal Keep track of the values in the input fields. Write the current value to the _inputValue property */
_handleInputChange(): void {
if (this._loading) {
return;
}

const value = this._inputEl.nativeElement.value;
this._writeControlValue(value);
this._updateAutocompleteOptionsOrGroups();
Expand All @@ -640,6 +644,10 @@ export class DtFilterField<T = any>

/** @internal */
_handleInputKeyDown(event: KeyboardEvent): void {
if (this._loading) {
return;
}

const keyCode = _readKeyCode(event);
if (keyCode === ENTER) {
// We need to prevent the default here, in case this filter field
Expand Down

0 comments on commit 7b593b7

Please sign in to comment.