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

[MIRROR] Dropdown selection fix #1076

Merged
merged 1 commit into from
Dec 12, 2023
Merged
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
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
Loading