Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(select): return value instead of array on single select #758

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/select/bl-select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe("bl-select", () => {

expect(removeAll).to.exist;
expect(event).to.exist;
expect(event.detail).to.eql([]);
expect(event.detail).to.null;
expect(el.options.length).to.equal(2);
expect(el.selectedOptions.length).to.equal(0);
expect(el.value).to.null;
Expand Down Expand Up @@ -246,7 +246,7 @@ describe("bl-select", () => {
const event = await oneEvent(el, "bl-select");

expect(event).to.exist;
expect(event.detail.length).to.equal(1);
expect(event.detail.value).to.equal("1");
expect(el.selectedOptions.length).to.equal(1);
});
it("should remove selected item if it is already selected", async () => {
Expand Down
23 changes: 12 additions & 11 deletions src/components/select/bl-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ export default class BlSelect<ValueType extends FormValue = string> extends Form
/**
* Fires when selection changes
*/
@event("bl-select") private _onBlSelect: EventDispatcher<ISelectOption<ValueType>[]>;

@event("bl-select") private _onBlSelect: EventDispatcher<
ISelectOption<ValueType> | ISelectOption<ValueType>[]
>;
private _connectedOptions: BlSelectOption<ValueType>[] = [];

private _cleanUpPopover: CleanUpFunction | null = null;
Expand Down Expand Up @@ -441,16 +442,16 @@ export default class BlSelect<ValueType extends FormValue = string> extends Form
}

private _handleSelectEvent() {
this._onBlSelect(
this._selectedOptions.map(
option =>
({
value: option.value,
selected: option.selected,
text: option.textContent,
} as ISelectOption<ValueType>)
)
const selectedOptions = this._selectedOptions.map(
option =>
({
value: option.value,
selected: option.selected,
text: option.textContent,
} as ISelectOption<ValueType>)
);

this._onBlSelect(this.multiple ? selectedOptions : selectedOptions[0]);
}

private _handleSingleSelect(optionItem: BlSelectOption<ValueType>) {
Expand Down