Skip to content

Commit

Permalink
[MIRROR] Dropdown selection fix [MDB IGNORE] (#1076)
Browse files Browse the repository at this point in the history
* Dropdown selection fix (#80249)

---------

Co-authored-by: SkyratBot <[email protected]>
Co-authored-by: Jeremiah <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent 8cc296f commit 4247849
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tgui/packages/tgui/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { Button } from './Button';
import { Icon } from './Icon';
import { Stack } from './Stack';

export interface DropdownEntry {
type DropdownEntry = {
displayText: string | number | ReactNode;
value: string | number | Enumerator;
}
};

type DropdownUniqueProps = { options: string[] | DropdownEntry[] } & Partial<{
type Props = { options: string[] | DropdownEntry[] } & Partial<{
buttons: boolean;
clipSelectedText: boolean;
color: string;
Expand All @@ -30,9 +30,13 @@ type DropdownUniqueProps = { options: string[] | DropdownEntry[] } & Partial<{
// you freaks really are just doing anything with this shit
selected: any;
width: string;
}>;
}> &
BoxProps;

export type DropdownProps = BoxProps & DropdownUniqueProps;
type State = {
selected?: string;
open: boolean;
};

const DEFAULT_OPTIONS = {
placement: 'left-start',
Expand All @@ -43,6 +47,7 @@ const DEFAULT_OPTIONS = {
},
],
};

const NULL_RECT: DOMRect = {
width: 0,
height: 0,
Expand All @@ -55,15 +60,10 @@ const NULL_RECT: DOMRect = {
toJSON: () => null,
} as const;

type DropdownState = {
selected?: string;
open: boolean;
};

const DROPDOWN_DEFAULT_CLASSNAMES = 'Layout Dropdown__menu';
const DROPDOWN_SCROLL_CLASSNAMES = 'Layout Dropdown__menu-scroll';

export class Dropdown extends Component<DropdownProps, DropdownState> {
export class Dropdown extends Component<Props, State> {
static renderedMenu: HTMLDivElement | undefined;
static singletonPopper: ReturnType<typeof createPopper> | undefined;
static currentOpenMenu: Element | undefined;
Expand All @@ -72,7 +72,7 @@ export class Dropdown extends Component<DropdownProps, DropdownState> {
Dropdown.currentOpenMenu?.getBoundingClientRect() ?? NULL_RECT,
};
menuContents: any;
state: DropdownState = {
state: State = {
open: false,
selected: this.props.selected,
};
Expand Down Expand Up @@ -342,7 +342,7 @@ export class Dropdown extends Component<DropdownProps, DropdownState> {
overflow: clipSelectedText ? 'hidden' : 'visible',
}}
>
{displayText || this.state.selected}
{this.state.selected || displayText}
</span>
{nochevron || (
<span className="Dropdown__arrow-button">
Expand Down

0 comments on commit 4247849

Please sign in to comment.