Set clearable prop to display the clear button in the right section. The button is not displayed when:
The component does not have a value
The component have a value but not opened, hovered or focused
The component is disabled
The component is readOnly
Choose an option
Helper Text
Source Code
Copy Code
Clearable.tsx
../../utils/Select/helpers
import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';import React from 'react';import { SelectItems } from '../../utils/Select/helpers';export function Clearable() { const [value, setValue] = React.useState<string[]>([]); return ( <div className="flex items-center justify-center px-8"> <Select items={SelectItems}
Show More
Using with Form
Remember to set name prop when using with form.
Select value must be an array string, other types are not supported. onValueChange function is called with an array string value as a single argument.
Choose an option
Helper Text
Source Code
Copy Code
OnValueChange.tsx
../../utils/Select/helpers
import { InfoCircleOutline } from '@ocean-network-express/magenta-ui/icons';import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';import React from 'react';import { SelectItems } from '../../utils/Select/helpers';export function OnValueChange() { const [value, setValue] = React.useState<string[]>([]); return ( <div className="flex items-center justify-center gap-6"> <Select
Show More
Async items
Bellow is an example of how to use the Select component with ListLoading and ListEmpty components.
Choose an option
Helper Text
Fetch
Source Code
Copy Code
Async.tsx
../../utils/Select/helpers
import { InfoCircleOutline } from '@ocean-network-express/magenta-ui/icons';import { Button, ListEmpty, ListItemText, ListLoading, Select, type SelectItem, SelectOption,} from '@ocean-network-express/magenta-ui/react';import React from 'react';
Show More
Controlled open state
You can control open Select component with open and onOpenChange props:
Trigger select
Choose an option
Source Code
Copy Code
Open.tsx
../../utils/Select/helpers
import { InfoCircleOutline } from '@ocean-network-express/magenta-ui/icons';import { Button, ListItemText, Select, SelectOption,} from '@ocean-network-express/magenta-ui/react';import React from 'react';import { SelectItems } from '../../utils/Select/helpers';export function Open() {
Show More
Multiple select
The Select component can handle multiple selections. It’s enabled with the multiple prop.
Like with the single selection, you can pull out the new value by accessing in the onValueChange callback. It’s always an array.
Default
Choose an option
Helper Text
Source Code
Copy Code
MultipleDefault.tsx
../../utils/Select/helpers
import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';import React from 'react';import { SelectItems } from '../../utils/Select/helpers';export function MultipleDefault() { const [value, setValue] = React.useState<string[]>([]); return ( <div className="flex items-center justify-center px-8"> <div className="max-w-[300px] mx-auto"> <Select
Show More
Checkboxes
Choose an option
Helper Text
Source Code
Copy Code
MultipleCheckboxes.tsx
../../utils/Select/helpers
import { Checkbox, ListItemText, Select, SelectOption,} from '@ocean-network-express/magenta-ui/react';import React from 'react';import { SelectItems } from '../../utils/Select/helpers';export function MultipleCheckboxes() { const [value, setValue] = React.useState<string[]>([]);
Show More
Tags
Select supports 2 styles text and tag for render value and can be changed by passing the renderValueType prop.
Default render value style is text.
Choose an option
Helper Text
Source Code
Copy Code
MultipleTags.tsx
../../utils/Select/helpers
import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';import React from 'react';import { SelectItems } from '../../utils/Select/helpers';export function MultipleTags() { const [value, setValue] = React.useState<string[]>([]); return ( <div className="flex items-center justify-center px-8"> <div className="max-w-[300px] mx-auto"> <Select
Show More
Limit Tags
You can use the limitTags prop to limit the number of displayed options when not focused.
The built-in callback action to delete selected item
className
The built-in className prop for the selected item is passed to the Tag component
deletable
The built-in deletable prop for the selected item is passed to the Tag component
data-visible-on-active
The built-in prop for a component that displays the selected item. If Select is set to limitTags, this prop will trigger show/hide behavior for the selected item.
disabled | readOnly | size
The props pass for a component that displays the selected item from Select
Option 1
Option 4
+1
Source Code
Copy Code
RenderSelectedItemTags.tsx
../../utils/Select/helpers
import { FileDataOutline } from '@ocean-network-express/magenta-ui/icons';import { ListItemText, Select, SelectOption, Tag, TagContent,} from '@ocean-network-express/magenta-ui/react';import React from 'react';import { DefaultSelectItems } from '../../utils/Select/helpers';
Show More
Grouping
Display categories with the ListSubheader component
Dangerous Container; Dry Container; Flatrack ContainerHelper Text
Source Code
Copy Code
Grouping.tsx
../../utils/Select/helpers
import { ListItemText, ListSubheader, Select, SelectOption,} from '@ocean-network-express/magenta-ui/react';import React from 'react';import { SelectItems } from '../../utils/Select/helpers';export function Grouping() { const [value, setValue] = React.useState<string[]>(['1', '2', '3']);
Show More
Max Height
When there are too many selected options in select field, which may break the UI layout, you can set max height allowing the field to scroll through className.
Dangerous Container
Dry Container
Flatrack Container
Tank Container
Crane Container
Source Code
Copy Code
MaxHeight.tsx
../../utils/Select/helpers
import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';import React from 'react';import { SelectItems } from '../../utils/Select/helpers';export function MaxHeight() { const [value, setValue] = React.useState<string[]>(['1', '2', '3', '4', '5']); return ( <div className="flex items-center justify-center px-8"> <div className="w-[400px]"> <Select
Show More
DropdownConfig
The dropdownConfig props allow you to set the CSS of the dropdown list.
Width/Height
Choose an option
Helper Text
Source Code
Copy Code
DropdownConfig.tsx
../../utils/Select/helpers
import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';import React from 'react';import { SelectItems } from '../../utils/Select/helpers';export function DropdownConfig() { const [value, setValue] = React.useState<string[]>([]); return ( <div className="flex justify-center items-center gap-4"> <div className="w-[500px]"> <Select
Show More
Padding
The padding prop controls the overflow padding of the dropdown list relative to the viewport edges.
Choose an option
Helper Text
Source Code
Copy Code
DropdownConfigPadding.tsx
../../utils/Select/helpers
import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';import React from 'react';import { SelectItems } from '../../utils/Select/helpers';export function DropdownConfigPadding() { const [value, setValue] = React.useState<string[]>([]); return ( <div className="flex items-center justify-center px-8"> <Select items={SelectItems}
Show More
Padding Content
The paddingContent prop allows you to set the padding of the dropdown list content.
Choose an option
Helper Text
Source Code
Copy Code
DropdownConfigInnerPadding.tsx
../../utils/Select/helpers
import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';import React from 'react';import { SelectItems } from '../../utils/Select/helpers';export function DropdownConfigInnerPadding() { const [value, setValue] = React.useState<string[]>([]); return ( <div className="flex items-center justify-center px-8"> <Select items={SelectItems}
Show More
Strategy
The strategy prop allows you to control the positioning strategy of the popover.