Skip to content
Sapphire UIv4.1.0

Native Select

Choose one value through the browser’s native select control. Use it for straightforward forms where platform behaviour is preferable to a custom popup.

Examples

Variants

JSX usage

Install this example’s dependencies, load the package stylesheet from Setup, and add Example CSS where shown. The snippet includes its local helpers.

bun add @kongmy-dev/sapphire-ui react react-dom
"use client";
import { Card } from "@kongmy-dev/sapphire-ui/card";
import { NativeSelect } from "@kongmy-dev/sapphire-ui/native-select";

function SelectVariants() {
  return (
    <div className="docs-native-select-demo sp-stack">
      <NativeSelect aria-label="Default plan">
        <option>Free</option>
        <option>Pro</option>
      </NativeSelect>
      <Card variant="dark">
        <NativeSelect variant="on-dark" aria-label="On dark plan">
          <option>Free</option>
          <option>Pro</option>
        </NativeSelect>
      </Card>
    </div>
  );
}

export default SelectVariants;
Example CSS

Load these demo styles alongside the package stylesheet for the same layout and surfaces.

.docs-native-select-demo {
  max-width: calc(var(--space-1) * 75);
}
HTML markup

Initial rendered HTML only. React handlers and portalled content require the JSX example; static HTML does not reproduce those interactions.

States

JSX usage

Install this example’s dependencies, load the package stylesheet from Setup, and add Example CSS where shown. The snippet includes its local helpers.

bun add @kongmy-dev/sapphire-ui react react-dom
"use client";
import { NativeSelect } from "@kongmy-dev/sapphire-ui/native-select";

function SelectStates() {
  return (
    <div className="docs-native-select-demo sp-stack">
      <NativeSelect disabled aria-label="Disabled plan">
        <option>Free</option>
      </NativeSelect>
      <NativeSelect
        aria-invalid="true"
        aria-describedby="select-example-error"
        aria-label="Invalid plan"
      >
        <option value="">Choose a plan</option>
      </NativeSelect>
      <p id="select-example-error">Choose an available plan.</p>
      <NativeSelect
        multiple
        aria-label="Multiple plans"
        defaultValue={['free']}
      >
        <option value="free">Free</option>
        <option value="pro">Pro</option>
      </NativeSelect>
    </div>
  );
}

export default SelectStates;
Example CSS

Load these demo styles alongside the package stylesheet for the same layout and surfaces.

.docs-native-select-demo {
  max-width: calc(var(--space-1) * 75);
}
HTML markup

Initial rendered HTML only. React handlers and portalled content require the JSX example; static HTML does not reproduce those interactions.

Controlled

JSX usage

Install this example’s dependencies, load the package stylesheet from Setup, and add Example CSS where shown. The snippet includes its local helpers.

bun add @kongmy-dev/sapphire-ui react react-dom
"use client";
import { useState } from "react";
import { NativeSelect } from "@kongmy-dev/sapphire-ui/native-select";

function SelectControlled() {
  const [plan, setPlan] = useState('free');
  return (
    <div className="docs-native-select-demo sp-stack">
      <NativeSelect
        aria-label="Controlled plan"
        value={plan}
        onChange={(event) => setPlan(event.currentTarget.value)}
      >
        <option value="free">Free</option>
        <option value="pro">Pro</option>
        <option value="enterprise" disabled>
          Enterprise
        </option>
      </NativeSelect>
      <output>{plan}</output>
    </div>
  );
}

export default SelectControlled;
Example CSS

Load these demo styles alongside the package stylesheet for the same layout and surfaces.

.docs-native-select-demo {
  max-width: calc(var(--space-1) * 75);
}
HTML markup

Initial rendered HTML only. React handlers and portalled content require the JSX example; static HTML does not reproduce those interactions.

Sizes

JSX usage

Install this example’s dependencies, load the package stylesheet from Setup, and add Example CSS where shown. The snippet includes its local helpers.

bun add @kongmy-dev/sapphire-ui react react-dom
"use client";
import { NativeSelect } from "@kongmy-dev/sapphire-ui/native-select";

function SelectSizes() {
  return (
    <div className="docs-native-select-demo sp-stack">
      <NativeSelect size="sm" aria-label="Small plan">
        <option>Free</option>
      </NativeSelect>
      <NativeSelect aria-label="Regular plan">
        <option>Free</option>
      </NativeSelect>
      <NativeSelect size="lg" aria-label="Large plan">
        <option>Free</option>
      </NativeSelect>
    </div>
  );
}

export default SelectSizes;
Example CSS

Load these demo styles alongside the package stylesheet for the same layout and surfaces.

.docs-native-select-demo {
  max-width: calc(var(--space-1) * 75);
}
HTML markup

Initial rendered HTML only. React handlers and portalled content require the JSX example; static HTML does not reproduce those interactions.

Props

Generated from the current public TypeScript signatures, including composed behaviour props. “—” means no default is declared in the local signature; forwarded behaviour defaults are not inferred.

NativeSelect

NativeSelect component props
PropTypeRequiredLocal default
childrenReactNodeYes—
variant"default" | "on-dark" | null | undefinedNo'default'
size"sm" | "lg" | "default" | null | undefinedNo'default'
Inherited HTML / React props (286)
NativeSelect common platform props
PropTypeRequiredLocal default
styleimport("react").CSSProperties | undefinedNo—
refimport("react").Ref<HTMLSelectElement> | undefinedNo—
defaultValuestring | number | readonly string[] | undefinedNo—
classNamestring | undefinedNo—
idstring | undefinedNo—
tabIndexnumber | undefinedNo—
roleimport("react").AriaRole | undefinedNo—
aria-labelstring | undefinedNo—
onChangeimport("react").ChangeEventHandler<HTMLSelectElement, HTMLSelectElement> | undefinedNo—
disabledboolean | undefinedNo—
namestring | undefinedNo—
valuestring | number | readonly string[] | undefinedNo—

All inherited prop names:

form slot style title ref key defaultChecked defaultValue suppressContentEditableWarning suppressHydrationWarning accessKey autoCapitalize autoFocus className contentEditable contextMenu dir draggable enterKeyHint hidden id lang nonce spellCheck tabIndex translate radioGroup role about content datatype inlist prefix property rel resource rev typeof vocab autoCorrect autoSave color itemProp itemScope itemType itemID itemRef results security unselectable popover popoverTargetAction popoverTarget inert inputMode is exportparts part aria-activedescendant aria-atomic aria-autocomplete aria-braillelabel aria-brailleroledescription aria-busy aria-checked aria-colcount aria-colindex aria-colindextext aria-colspan aria-controls aria-current aria-describedby aria-description aria-details aria-disabled aria-dropeffect aria-errormessage aria-expanded aria-flowto aria-grabbed aria-haspopup aria-hidden aria-invalid aria-keyshortcuts aria-label aria-labelledby aria-level aria-live aria-modal aria-multiline aria-multiselectable aria-orientation aria-owns aria-placeholder aria-posinset aria-pressed aria-readonly aria-relevant aria-required aria-roledescription aria-rowcount aria-rowindex aria-rowindextext aria-rowspan aria-selected aria-setsize aria-sort aria-valuemax aria-valuemin aria-valuenow aria-valuetext dangerouslySetInnerHTML onCopy onCopyCapture onCut onCutCapture onPaste onPasteCapture onCompositionEnd onCompositionEndCapture onCompositionStart onCompositionStartCapture onCompositionUpdate onCompositionUpdateCapture onFocus onFocusCapture onBlur onBlurCapture onChange onChangeCapture onBeforeInput onBeforeInputCapture onInput onInputCapture onReset onResetCapture onSubmit onSubmitCapture onInvalid onInvalidCapture onLoad onLoadCapture onError onErrorCapture onKeyDown onKeyDownCapture onKeyPress onKeyPressCapture onKeyUp onKeyUpCapture onAbort onAbortCapture onCanPlay onCanPlayCapture onCanPlayThrough onCanPlayThroughCapture onDurationChange onDurationChangeCapture onEmptied onEmptiedCapture onEncrypted onEncryptedCapture onEnded onEndedCapture onLoadedData onLoadedDataCapture onLoadedMetadata onLoadedMetadataCapture onLoadStart onLoadStartCapture onPause onPauseCapture onPlay onPlayCapture onPlaying onPlayingCapture onProgress onProgressCapture onRateChange onRateChangeCapture onSeeked onSeekedCapture onSeeking onSeekingCapture onStalled onStalledCapture onSuspend onSuspendCapture onTimeUpdate onTimeUpdateCapture onVolumeChange onVolumeChangeCapture onWaiting onWaitingCapture onAuxClick onAuxClickCapture onClick onClickCapture onContextMenu onContextMenuCapture onDoubleClick onDoubleClickCapture onDrag onDragCapture onDragEnd onDragEndCapture onDragEnter onDragEnterCapture onDragExit onDragExitCapture onDragLeave onDragLeaveCapture onDragOver onDragOverCapture onDragStart onDragStartCapture onDrop onDropCapture onMouseDown onMouseDownCapture onMouseEnter onMouseLeave onMouseMove onMouseMoveCapture onMouseOut onMouseOutCapture onMouseOver onMouseOverCapture onMouseUp onMouseUpCapture onSelect onSelectCapture onTouchCancel onTouchCancelCapture onTouchEnd onTouchEndCapture onTouchMove onTouchMoveCapture onTouchStart onTouchStartCapture onPointerDown onPointerDownCapture onPointerMove onPointerMoveCapture onPointerUp onPointerUpCapture onPointerCancel onPointerCancelCapture onPointerEnter onPointerLeave onPointerOver onPointerOverCapture onPointerOut onPointerOutCapture onGotPointerCapture onGotPointerCaptureCapture onLostPointerCapture onLostPointerCaptureCapture onScroll onScrollCapture onScrollEnd onScrollEndCapture onWheel onWheelCapture onAnimationStart onAnimationStartCapture onAnimationEnd onAnimationEndCapture onAnimationIteration onAnimationIterationCapture onToggle onBeforeToggle onTransitionCancel onTransitionCancelCapture onTransitionEnd onTransitionEndCapture onTransitionRun onTransitionRunCapture onTransitionStart onTransitionStartCapture multiple disabled name value required autoComplete

ARIA attributes and native event handlers keep their React types. data-* attributes are also accepted by React.

Setup

bun add @kongmy-dev/sapphire-ui react react-dom

For an app using package components throughout, load the full stylesheet once. Add this component import where you use it.

import "@kongmy-dev/sapphire-ui/sapphire.css";
import { NativeSelect } from "@kongmy-dev/sapphire-ui/native-select";

Mixing package and vendored components? Follow application setup.

Search documentation