Skip to content

Commit

Permalink
fix(select): popover and selected issue (#257)
Browse files Browse the repository at this point in the history
Co-authored-by: Mustafa Adıgüzel <[email protected]>
Co-authored-by: Murat Çorlu <[email protected]>
  • Loading branch information
3 people authored Sep 29, 2022
1 parent 54ca2c0 commit 4cd7d67
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/components/select/bl-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,19 @@ export default class BlSelect extends LitElement {
open() {
this._isPopoverOpen = true;
this._setupPopover();
document.addEventListener('click', this._clickOutsideHandler);
}

close() {
this._isPopoverOpen = false;
this._cleanUpPopover && this._cleanUpPopover();
document.removeEventListener('click', this._clickOutsideHandler);
}

private _clickOutsideHandler = (event: MouseEvent) => {
const target = event.target as HTMLElement;
const eventPath = event.composedPath() as HTMLElement[];

if (!this.contains(target) && this._isPopoverOpen) {
if (!eventPath?.find(el => el.tagName === 'BL-SELECT')?.contains(this)) {
this.close();
this._checkRequired();
}
Expand Down Expand Up @@ -174,13 +176,10 @@ export default class BlSelect extends LitElement {

connectedCallback() {
super.connectedCallback();

document.addEventListener('click', this._clickOutsideHandler);
}
disconnectedCallback() {
super.disconnectedCallback();

document.removeEventListener('click', this._clickOutsideHandler);
this._cleanUpPopover && this._cleanUpPopover();
}

Expand Down Expand Up @@ -266,7 +265,7 @@ export default class BlSelect extends LitElement {
}

private _handleSingleSelect(optionItem: ISelectOption) {
const oldItem = this._connectedOptions.find(option => option.selected);
const oldItem = this._connectedOptions.find(option => option.value !== optionItem.value && option.selected);

if (oldItem) {
oldItem.selected = false;
Expand Down

0 comments on commit 4cd7d67

Please sign in to comment.