import * as React from 'react'; import { OverrideProps } from '@mui/types'; import { CreateSlotsAndSlotProps, SlotCommonProps, SlotProps } from '../types/slot'; import { SelectValue } from '../internal/hooks/useSelect'; import { SelectOption } from '../internal/hooks/useOption'; import { MenuProps } from '../Menu'; export interface DropdownSlots { /** * The component that renders the root. * @default 'div' */ root?: React.ElementType; /** * The component that renders the button. * @default 'button' */ button?: React.ElementType; /** * The component that renders the start decorator. * @default 'span' */ startDecorator?: React.ElementType; /** * The component that renders the end decorator. * @default 'span' */ endDecorator?: React.ElementType; /** * The component that renders the indicator. * @default 'span' */ indicator?: React.ElementType; /** * The component that renders the listbox. * @default 'ul' */ listbox?: React.ElementType; /** * The component that renders the error state. * @default 'span' */ errorStateIcon?: React.ElementType; } export type DropdownSlotsAndSlotProps = CreateSlotsAndSlotProps>; button: SlotProps<'button', object, DropdownOwnerState>; startDecorator: SlotProps<'span', object, DropdownOwnerState>; endDecorator: SlotProps<'span', object, DropdownOwnerState>; indicator: SlotProps<'span', object, DropdownOwnerState>; listbox: SlotProps<'ul', Omit, DropdownOwnerState>; errorStateIcon: SlotProps<'span', object, DropdownOwnerState>; }>; export interface DropdownTypeMap { props: P & { /** * A ref for imperative actions. It currently only supports `focusVisible()` action. */ action?: React.Ref<{ focusVisible(): void; }>; /** * Name of the dropdown. */ name?: string; /** * Text to show when there is no selected value. */ placeholder?: React.ReactNode; /** * If `true`, the select value cannot be empty when submitting form. * @default false */ required?: boolean; /** * If `true`, the dropdown is disabled. * @default false */ disabled?: boolean; /** * If `true`, the dropdown is under error state. * @default false */ error?: boolean; /** * If `true`, the dropdown is under readOnly state. * @default false */ readOnly?: boolean; /** * If `true`, the dropdown is focused during the first mount * @default false */ autoFocus?: boolean; /** * If `true`, the dropdown will take up the full width of its container. * @default false */ fullWidth?: boolean; /** * Leading adornment for the dropdown select. */ startDecorator?: React.ReactNode; /** * Trailing adornment for the dropdown select. */ endDecorator?: React.ReactNode; /** * The end indicator for the dropdown select. */ indicator?: React.ReactNode | ((open: boolean) => React.ReactNode); /** * The size of the dropdown. * @default 'medium' */ size?: 'small' | 'medium' | 'large'; /** * If `true`, `value` must be an array and the menu will support multiple selections. * @default false */ multiple?: Multiple; /** * A function to convert the currently selected value to a string. * Used to set a value of a hidden input associated with the select, * so that the selected value can be posted with a form. */ getSerializedValue?: (option: SelectValue, Multiple>) => React.InputHTMLAttributes['value']; /** * The default selected value. Use when the component is not controlled. */ defaultValue?: SelectValue; /** * The selected value. Use when the component is controlled. */ value?: SelectValue; /** * Function that renders the selected value. */ renderValue?: (option: SelectValue, Multiple>) => React.ReactNode; /** * Callback fired when an option is selected. */ onChange?: (event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null, value: SelectValue) => void; /** * `id` attribute of the listbox element. * Also used to derive the `id` attributes of options. */ listboxId?: string; /** * If `true`, the dropdown will be initially open. * @default false */ defaultListboxOpen?: boolean; /** * Controls the open state of the select's listbox. * @default undefined */ listboxOpen?: boolean; /** * Callback fired when the component requests to be opened. * Use in controlled mode (see listboxOpen). */ onListboxOpenChange?: (isOpen: boolean) => void; /** * Triggered when focus leaves the menu and the menu should close. */ onClose?: () => void; /** * Determines whether to display an error state icon at the end of `Dropdown` component. * This option only takes effect if the `error` property is set to `true`. * @default true */ showErrorIcon?: boolean; } & DropdownSlotsAndSlotProps; defaultComponent: D; } export type DropdownProps['defaultComponent'], P = SlotCommonProps> = OverrideProps, D>; export interface DropdownOwnerState extends DropdownProps { /** * If `true`, the select button's focus is visible. */ focusVisible?: boolean; /** * If `true`, the select dropdown is open. */ open: boolean; /** * If `true`, the select button is active. */ active: boolean; /** * If `true`, the select value is filled. */ filled: boolean; }