Skip to content

Commit

Permalink
feat(dropdown-select): ensure single dropdown open at a time (#2307)
Browse files Browse the repository at this point in the history
Implement global state to track the active dropdown. Modify handleClick method to close any other open dropdown before opening the clicked one. This ensures that only one dropdown can be open at a time.
  • Loading branch information
MihailsFX1nce authored Mar 28, 2024
1 parent 2e065d5 commit 2ad95bd
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
State,
Watch,
Event,
EventEmitter,
VNode,
type EventEmitter,
type VNode,
} from '@stencil/core';
import classNames from 'classnames';
import statusNote from '../../utils/status-note';
Expand Down Expand Up @@ -228,6 +228,8 @@ function isInView(element: HTMLElement) {
);
}

let activeDropdown = null;

@Component({
tag: 'scale-dropdown-select',
styleUrl: 'dropdown-select.css',
Expand Down Expand Up @@ -461,7 +463,15 @@ export class DropdownSelect {
};

handleClick = () => {
// * This is a fix to prevent the dropdown from being opened when the user clicks on another combobox.
// ! https://github.com/telekom/scale/issues/2285
if (activeDropdown && activeDropdown !== this) {
activeDropdown.setOpen(false);
}

this.setOpen(!this.open);
activeDropdown = this;

const indexOfValue = readOptions(this.hostElement).findIndex(
({ value }) => value === this.value
);
Expand Down

0 comments on commit 2ad95bd

Please sign in to comment.