Skip to main content

DropdownFabric component

Component for rendering a dropdown list control.

📝 Signature​

DropdownFabric(props: {
styles: {
backgroundColor: string;
borderColor: string;
borderSize?: number;
roundness?: number;
textColor?: string;
errorColor: string;
scale?: number;
};
options: IDropdownFabricOption[];
id?: string;
placeholder?: string;
required?: boolean;
disabled?: boolean;
readOnly?: boolean;
error?: boolean;
tabIndex?: number;
value?: string | Value;
ariaDescribedBy?: string;
onChange?: (id: string) => void;
onFocus?: (e: FocusEvent) => void;
onBlur?: (e: FocusEvent) => void;
onAutoFocus?: (el: HTMLSelectElement | null) => void;
onSubmit?: () => void;
onCancel?: () => void;
}): JSX.Element

📇 Props​

NameTypeOptionalDescription
stylesobjectNoSpecifies the styles for the dropdown component. Supports the following styles:
- backgroundColor: Background color for the component;
- borderColor: Border color for the component;
- borderSize: Optional border size in pixels for the component;
- roundness: Optional roundness in pixels for the component;
- textColor: Optional text color for the component;
- errorColor: Error color for the component;
- scale: Optional scale factor for the component (defaults to 1).
optionsIDropdownFabricOption[]NoSpecifies the options for the dropdown (see IDropdownFabricOption).
idstringYesOptional identifier for the component.
placeholderstringYesOptional placeholder that is shown when there is no option selected.
requiredbooleanYesSpecifies if the component is required.
disabledbooleanYesSpecifies if the component is disabled.
readOnlybooleanYesSpecifies if the component is read-only.
errorbooleanYesSpecifies if the component has an error.
tabIndexnumberYesSpecifies the tabindex for the component.
valuestring | ValueYesSpecifies the value for the component. When a string is supplied, this should be the identifier of the initial dropdown option that should be selected. When a Value instance is supplied, the initial option is selected according to the current value in that instance. When the selected option is changed, the value in the Value instance is automatically updated.
ariaDescribedBystringYesSpecifies the aria-describedby identifier of the element that describes the component.
onChange(id: string) => voidYesInvoked when the selected option is changed.
onFocus(e: FocusEvent) => voidYesInvoked when the component gets focus.
onBlur(e: FocusEvent) => voidYesInvoked when the component loses focus.
onAutoFocus(el: HTMLSelectElement | null) => voidYesInvoked when the HTML element of the component is available for auto-focus.
onSubmit() => voidYesInvoked when the user presses the Shift + Enter key combination or the Tab key (this event is often used to go to the next input control in a form).
onCancel() => voidYesInvoked when the user presses the Shift + Tab key combination (this event is often used to go to the previous input control in a form).

↩ī¸ Return value​

Returns the JSX.Element for the component.

👩‍đŸ’ģ Example​

import { DropdownFabric } from "@tripetto/runner-fabric/components/dropdown";

const DropdownExample = () => (
<DropdownFabric
styles={{
backgroundColor: "white",
borderColor: "black",
errorColor: "red"
}}
options={[
{
id: "1",
name: "Option 1",
},
{
id: "2",
name: "Option 2",
}
]}
onChange={(id) => console.log(`Selected: ${id}`)}
/>
);

⛓ī¸ Interfaces​


🔗 IDropdownFabricOption​

Describes the interface for a dropdown option.

Type declaration​

interface IDropdownFabricOption {
/* Identifier for the option. */
id: string;

/* Name for the option. */
name: string;

/* Value for the option. */
value?: string;
}