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

Commit

Permalink
feat(filter-field): Add disable state to the option without group
Browse files Browse the repository at this point in the history
  • Loading branch information
RuzzleDuzzle authored and tomheller committed Aug 23, 2021
1 parent 0630758 commit d25f2ad
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/dev/src/filter-field/testdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const TEST_DATA_PARTIAL_2 = {
{ name: 'Zug' },
{ name: 'Schaffhausen' },
{ name: 'Luzern' },
{ name: 'St. Gallen' },
{ name: 'St. Gallen (disabled)', disabled: true },
],
partial: true,
};
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 @@ -124,6 +124,7 @@
<ng-template #options>
<dt-option
[value]="optionOrGroupDef"
[disabled]="optionOrGroupDef.option!.disabled"
[attr.title]="_getTitle(optionOrGroupDef.option)"
>
<dt-highlight [term]="_inputValue">{{
Expand Down
45 changes: 45 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 @@ -1185,6 +1185,51 @@ describe('DtFilterField', () => {
expect(options[3].textContent).toContain('St. Gallen');
}));

it('should disable partial autocomplete option without a group', fakeAsync(() => {
const DATA = {
autocomplete: [
{
name: 'CH (async, partial)',
async: true,
autocomplete: [],
},
],
};

const DATA_PARTIAL = {
name: 'CH (async, partial)',
autocomplete: [{ name: 'Zürich', disabled: true }],
partial: true,
};

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

getAndClickOption(overlayContainerElement, 0);

let options = getOptions(overlayContainerElement);
expect(options).toHaveLength(0);

let hintPanel = getPartialResultsHintPanel(overlayContainerElement);
expect(hintPanel).toBeNull();

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

hintPanel = getPartialResultsHintPanel(overlayContainerElement);
expect(hintPanel).not.toBeNull();

options = getOptions(overlayContainerElement);
expect(options).toHaveLength(1);

// dt-option-disabled
expect(options[0].getAttribute('class')).toContain('dt-option-disabled');
}));

it('should mark the input as readonly while loading async data', () => {
const DATA = {
autocomplete: [
Expand Down

0 comments on commit d25f2ad

Please sign in to comment.