Select

A Select component allows users to choose a single option or multiple options from the provided list of options.


Basic

Helper Text

Source Code

import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { SelectItems } from '../../utils/Select/helpers';

export function Basic() {
  const [value, setValue] = React.useState<string[]>([]);

  return (
    <div className="flex items-center justify-center px-8">
      <Select
        items={SelectItems}

Variants

  • Select supports 2 variants: defaultand ghost.

Source Code

import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { SelectItems } from '../../utils/Select/helpers';

type SelectVariant = 'default' | 'ghost';

const SELECT_VARIANTS: SelectVariant[] = ['default', 'ghost'];

export function Variants() {
  const [selectedValues, setSelectedValues] = React.useState<string[]>([]);

Sizes

  • Select supports 4 sizes sm, md, lg and responsive and can be changed by passing the size prop.
  • Default size is lg.

Source Code

import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { SelectItems } from '../../utils/Select/helpers';

type SelectSize = 'sm' | 'md' | 'lg';

const SELECT_SIZES: SelectSize[] = ['sm', 'md', 'lg'];

export function Sizes() {
  const [selectedValue, setSelectedValue] = React.useState<string[]>([]);
  • With size responsive, the component will be responsive to the viewport.

Screen prefix

Screen width

Component size

xsxl0px 1279pxsm
xl3xl1280px 1919pxmd
3xl1920pxlg

Source Code

import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { SelectItems } from '../../utils/Select/helpers';

export function SizesResponsive() {
  const [value, setValue] = React.useState<string[]>([]);

  return (
    <div className="flex gap-x-24 flex-col items-center">
      <Select
        items={SelectItems}

With Icons

  • Select supports icons from the @ocean-network-express/magenta-ui/icons package.
  • The prop leftContent support to add icon or other content to the left side.

Source Code

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 WithIcons() {
  const [value, setValue] = React.useState<string[]>([]);

  return (
    <div className="flex items-center justify-center px-8">
      <Select

Alignment Label

  • Select supports 3 type of Alignment Label top, left and inline and can be changed by passing the labelAlignment prop.
  • Default Alignment is top.
  • When using inline Alignment with leftContent, the leftContent will be override by Label
Helper Text
Helper Text
Helper Text

Source Code

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';

type LabelAlignmentConfig = {
  alignment: 'top' | 'left' | 'inline';
  labelText: string;
};

const LABEL_ALIGNMENT_CONFIGS: LabelAlignmentConfig[] = [

Disabled

  • Disabled state can be enabled by setting disabled prop to true.
Helper Text
Helper Text

Source Code

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 { SelectItemsWithDisabled } from '../../utils/Select/helpers';

export function Disabled() {
  const [value, setValue] = React.useState<string[]>([]);

  return (
    <div className="flex flex-row gap-6 items-center justify-center">
      <Select

Loading

  • Loading state can be enabled by setting loading prop to true, when in loading state, the selected value will be replaced by placeholder text.
Helper Text

Source Code

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 { SelectItemsWithDisabled } from '../../utils/Select/helpers';

export function Loading() {
  const [value, setValue] = React.useState<string[]>([]);

  return (
    <div className="flex flex-row gap-20 justify-center">
      <Select

Helper text

  • Helper text can be changed by passing the helperText prop.
  • The helper text can be displayed in 2 ways: inline and tooltip and can be changed by passing the renderHelperType prop.

Inline (default)

Helper Text

Source Code

import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { SelectItems } from '../../utils/Select/helpers';

export function HelperTextDefault() {
  const [value, setValue] = React.useState<string[]>([]);

  return (
    <div className="flex items-center justify-center px-8">
      <Select
        items={SelectItems}

Tooltip

Source Code

import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { SelectItems } from '../../utils/Select/helpers';

export function HelperTextTooltip() {
  const [value, setValue] = React.useState<string[]>([]);

  return (
    <div className="flex items-center justify-center px-8">
      <Select
        items={SelectItems}

States

  • Currently, Select supports 3 state is error, warning and success and can be changed by passing the state prop.
  • As use case of the tooltip, you can use the renderHelperType='tooltip' to display the error message in the tooltip.
  • The tooltip content render by helperText prop value, and it accept ReactNode.

Inline (default)

Error message goes here
Warning message goes here
Success message goes here

Source Code

import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { SelectItems } from '../../utils/Select/helpers';

type SelectStateConfig = {
  state: 'error' | 'warning' | 'success';
  label: string;
  helperText: string;
};

const SELECT_STATE_CONFIGS: SelectStateConfig[] = [

Tooltip

Source Code

import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { SelectItems } from '../../utils/Select/helpers';

type SelectStateConfig = {
  state: 'error' | 'warning' | 'success';
  label: string;
  helperText: string;
};

const SELECT_STATE_CONFIGS: SelectStateConfig[] = [

Clearable

Helper Text

Source Code

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}

Using with Form

Helper Text

Source Code

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

Async items

Helper Text

Source Code

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';

Controlled open state

Source Code

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() {

Multiple select

Default

Helper Text

Source Code

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

Checkboxes

Helper Text

Source Code

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[]>([]);

Tags

Helper Text

Source Code

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

Limit Tags

Dangerous Container
Dry Container
+1
Flatrack Container

Source Code

import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { SelectItems } from '../../utils/Select/helpers';

export function LimitTags() {
  const [value, setValue] = React.useState<string[]>(['1', '2', '3']);
  const [value2, setValue2] = React.useState<string[]>(['1', '2', '3']);

  return (
    <div className="flex justify-center px-8">
      <div className="grid gap-20 max-w-[400px]">

Limit Tags Idle

Option 1
Option 4
+1

Source Code

import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { DefaultSelectItems } from '../../utils/Select/helpers';

export function LimitTagsIdle() {
  const [value, setValue] = React.useState<string[]>(['1', '4', '3']);
  const [value2, setValue2] = React.useState<string[]>(['1', '4', '3']);

  return (
    <div className="flex justify-center px-8">
      <div className="grid gap-5">

Custom Render Selected Items

Source Code


renderSelectedItems?: React.FC<{
  selectedItems: SelectedItemTagProps<SelectItem>[];
  numberOfHiddenItem?: number | undefined;
}>
    

Source Code


type SelectedItemTagProps<TValue = SelectItem> = {
  item: TValue;
  onDeleted: () => void;
  className?: string;
  'data-visible-on-active'?: boolean;
  deletable?: boolean;
} & Pick<SelectProps, 'disabled' | 'readOnly' | 'size'>
    

Prop

Description

itemSelected item data type SelectItem
onDeleted

The built-in callback action to delete selected item

classNameThe built-in className prop for the selected item is passed to the Tag component
deletableThe built-in deletable prop for the selected item is passed to the Tag component
data-visible-on-activeThe 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 | sizeThe props pass for a component that displays the selected item from Select
Option 1
Option 4
+1

Source Code

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';

Grouping

Helper Text

Source Code

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']);

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

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

The dropdownConfig props allow you to set the CSS of the dropdown list.

Width/Height

Helper Text

Source Code

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

Padding

Helper Text

Source Code

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}

Padding Content

Helper Text

Source Code

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}

Strategy

Source Code


<Select dropdownConfig={{ strategy: 'fixed' }} {...otherProps}>
// render logic children
</Select>
    

Placement

Source Code

import { ListItemText, Select, SelectOption } from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { SelectItems } from '../../utils/Select/helpers';

const PLACEMENTS = [
  { placement: 'bottom-start' as const, label: 'Bottom start' },
  { placement: 'top-end' as const, label: 'Top end' },
  { placement: 'right-end' as const, label: 'Right end' },
  { placement: 'left-start' as const, label: 'Left start' },
];

Customized tags

Option 1
Option 2
+1
Option 3

Source Code

import {
  Checkbox,
  ListItem,
  ListItemText,
  Select,
  SelectOption,
  Tag,
  TagContent,
} from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { CustomSelectItems, SelectItemsColor } from '../../utils/Select/helpers';

Custom Order Selected

Source Code

import {
  Checkbox,
  ListItem,
  ListItemText,
  Select,
  SelectOption,
  Tag,
  TagContent,
} from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { CustomSelectItems, SelectItemsColor } from '../../utils/Select/helpers';

Re-order ListItem

Option 1
Option 2 but with very long label
+1
Option 3
Helper Text

Source Code

import {
  ListItemText,
  ListSubheader,
  Select,
  SelectOption,
} from '@ocean-network-express/magenta-ui/react';
import React from 'react';

import { DefaultSelectItems } from '../../utils/Select/helpers';

export function ReOrderListItem() {
  const [value, setValue] = React.useState<string[]>(['1', '2', '3']);

Search Input & Select All

Option 1
Option 2
+1
Option 3

Source Code

import { InboxOutline, SearchOutline } from '@ocean-network-express/magenta-ui/icons';
import {
  Checkbox,
  Input,
  ListEmpty,
  ListItem,
  ListItemText,
  Select,
  SelectOption,
  Tag,
  TagContent,
} from '@ocean-network-express/magenta-ui/react';

Was this page helpful?