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

Commit

Permalink
fix(combobox): Fixes an issue with programmatic setting of the value …
Browse files Browse the repository at this point in the history
…to null.

Fixes APM-272145
  • Loading branch information
tomheller committed Dec 11, 2020
1 parent 5a10dc0 commit d457785
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
10 changes: 10 additions & 0 deletions apps/components-e2e/src/components/combobox/combobox.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
comboboxInput,
option,
loadingIndicator,
resetValueButton,
} from './combobox.po';

fixture('Combobox')
Expand Down Expand Up @@ -126,3 +127,12 @@ test('should not reset the value when hitting continuously typing the backspace
.expect(option.nth(2).textContent)
.contains('Value 3');
});

test('should reset the value when setting the value programmatically to null', async (testController: TestController) => {
await testController
.expect(comboboxInput.value)
.eql('Value 1')
.click(resetValueButton)
.expect(comboboxInput.value)
.eql('');
});
4 changes: 4 additions & 0 deletions apps/components-e2e/src/components/combobox/combobox.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
{{ option.name }}
</dt-option>
</dt-combobox>

<button id="resetValue" (click)="_initialValue = null">
Set value to null
</button>
2 changes: 2 additions & 0 deletions apps/components-e2e/src/components/combobox/combobox.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ export const option = comboboxOverlayPane.find('.dt-option');
export const loadingIndicator = Selector(
'.dt-combobox-postfix.dt-combobox-spinner',
);

export const resetValueButton = Selector('#resetValue');
2 changes: 1 addition & 1 deletion apps/components-e2e/src/components/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function optionFilter(
export class DtE2ECombobox {
@ViewChild(DtCombobox) combobox: DtCombobox<any>;

_initialValue = allOptions[0];
_initialValue: ExampleComboboxOption | null = allOptions[0];
_options = [...allOptions];
_loading = false;
_displayWith = (option: ExampleComboboxOption) => option.name;
Expand Down
11 changes: 11 additions & 0 deletions libs/barista-components/experimental/combobox/src/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,17 @@ export class DtCombobox<T>

/** Updates the selection by value using selection model and keymanager to handle the active item */
private _setSelectionByValue(value: T, triggered: boolean = true): void {
// If value is being reset programmatically
if (value === null && this._selectionModel) {
// Deselect all values in the selection model
for (const selected of this._selectionModel.selected) {
this._selectionModel.deselect(selected);
}
this._writeValue();
this._changeDetectorRef.markForCheck();
return;
}

const correspondingOption = this._selectValue(value, triggered);

// Shift focus to the active item
Expand Down

0 comments on commit d457785

Please sign in to comment.