Native Select
Grouped Options
A native select with sections on <optgroup>: identical names stop being confusing because the system labels the groups itself.
- select
- optgroup
- native
- grouping
Preview
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/nativeselect-002?lang=en
Inside each section addresses are sorted by load.
Show the full instructions
What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.
# Install and place "nativeselect-002" (Grouped Options) from VibeUI
## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/nativeselect-002.json
Registry item: https://vibeui.ru/r/nativeselect-002.json
Installs to: components/vibeui/nativeselect-002.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.
Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.
## 2. What it is
A native select with sections on <optgroup>: identical names stop being confusing because the system labels the groups itself.
A native select with sections: the system draws and announces the group headings. Zero dependencies, one file, no client JS.
## 3. How to use it
import { Nativeselect002 } from "@/components/vibeui/nativeselect-002"
<Nativeselect002
label="Ship to"
hint="Inside each section addresses are sorted by load."
groups={[{ label: "Warehouses", options: ["Main, north"] }]}
/>
Read the installed file for the full prop list.
## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.
Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)
## 5. Keep exactly as installed
- the local --vibeui-nativeselect-002-* palette — do not swap it for your theme tokens
- the built-in <optgroup>: it gives a non-clickable heading and a spoken section name for free
- the label attribute on optgroup — without it the section exists only visually
- resetting option back to normal weight: otherwise the choices inherit the heading's boldness
- the native list as a whole: on a phone the system shows sections the familiar way, a hand-built menu cannot
- the block's own light surface: without it the dark label disappears on a dark background
## 6. You may change
- the field name through label, the explanation through hint and the sections through groups
- the focus color through accent
- the weight and color of the section headings
- the section order: it is exactly the array order
## 7. Rules
- Nested sections are impossible: an <optgroup> cannot contain another one, that is an HTML limit.
- With more than five sections and close to a hundred options, take a combobox with search: scrolling a system wheel is painful.
- Some mobile shells render the section heading at the same size as options — do not rely on the visual difference.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.
## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.For developers
npx shadcn@latest add https://vibeui.ru/r/nativeselect-002.jsonhttps://vibeui.ru/r/nativeselect-002.jsonКомпонент самодостаточен: один файл, без зависимостей, палитра в локальных переменных --vibeui-nativeselect-002-*. Серверный: из хуков только useId. Разделы объявлены штатным <optgroup label>: браузер сам рисует заголовки некликабельными, а экранный диктор произносит название раздела перед пунктом — в самодельном списке то же самое приходится собирать из role="group" и aria-labelledby. Начертание заголовков — единственное, на что можно влиять внутри раскрытого списка, поэтому optgroup получает font-weight и цвет, а option возвращает обычный вес. Стрелка нарисована двумя гранями и не ловит клики.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
import { useId } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Nativeselect002Group = {
label: string
options: string[]
}
export type Nativeselect002Props = Omit<
ComponentPropsWithoutRef<"select">,
"children" | "size"
> & {
label?: string
hint?: string
groups?: Nativeselect002Group[]
accent?: string
}
// Идея компонента: длинный плоский список одинаково называющихся пунктов
// не читается — «Основной» есть и у складов, и у офисов. <optgroup> даёт
// системе заголовки разделов: она сама рисует их некликабельными и сама
// произносит название раздела перед пунктом. Своими силами такое в
// кастомном списке приходится городить ролями и разметкой.
const STYLES = `
:where([data-vibeui-block="nativeselect-002"]){
--vibeui-nativeselect-002-surface:oklch(1 0 0);
--vibeui-nativeselect-002-surface-border:oklch(0.91 0.006 265);
--vibeui-nativeselect-002-fg:oklch(0.24 0.016 265);
--vibeui-nativeselect-002-muted:oklch(0.54 0.014 265);
--vibeui-nativeselect-002-field-border:oklch(0.85 0.01 265);
--vibeui-nativeselect-002-accent:oklch(0.5 0.16 165);
--vibeui-nativeselect-002-radius:0.625rem;
--vibeui-nativeselect-002-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="nativeselect-002"]{
box-sizing:border-box;width:100%;max-width:22rem;
padding:1rem;border-radius:0.875rem;
background:var(--vibeui-nativeselect-002-surface);
border:1px solid var(--vibeui-nativeselect-002-surface-border);
font-family:var(--vibeui-nativeselect-002-font);color:var(--vibeui-nativeselect-002-fg);
display:flex;flex-direction:column;gap:0.375rem;
}
[data-vibeui-block="nativeselect-002"] label{
font-size:0.875rem;font-weight:600;line-height:1.3;cursor:pointer;
}
[data-vibeui-block="nativeselect-002"] [data-part="field"]{position:relative;display:flex}
[data-vibeui-block="nativeselect-002"] select{
appearance:none;-webkit-appearance:none;
box-sizing:border-box;width:100%;height:2.5rem;
padding:0 2.25rem 0 0.75rem;
font:inherit;font-size:0.9375rem;line-height:1.2;
color:var(--vibeui-nativeselect-002-fg);
background:var(--vibeui-nativeselect-002-surface);
border:1px solid var(--vibeui-nativeselect-002-field-border);
border-radius:var(--vibeui-nativeselect-002-radius);
cursor:pointer;
transition:border-color .16s ease,box-shadow .16s ease;
}
[data-vibeui-block="nativeselect-002"] select:focus-visible{
outline:none;border-color:var(--vibeui-nativeselect-002-accent);
box-shadow:0 0 0 3px color-mix(in oklab,var(--vibeui-nativeselect-002-accent) 22%,transparent);
}
/* Заголовки разделов рисует система, но начертание она берёт отсюда:
это единственное, на что мы влияем внутри раскрытого списка. */
[data-vibeui-block="nativeselect-002"] optgroup{
font-weight:600;font-style:normal;color:var(--vibeui-nativeselect-002-muted);
}
[data-vibeui-block="nativeselect-002"] option{
font-weight:400;color:var(--vibeui-nativeselect-002-fg);
}
[data-vibeui-block="nativeselect-002"] [data-part="arrow"]{
position:absolute;right:0.875rem;top:50%;pointer-events:none;
width:0.4375rem;height:0.4375rem;
border-right:1.5px solid var(--vibeui-nativeselect-002-muted);
border-bottom:1.5px solid var(--vibeui-nativeselect-002-muted);
translate:0 -0.1875rem;rotate:45deg;
}
[data-vibeui-block="nativeselect-002"] [data-part="hint"]{
margin:0;font-size:0.8125rem;line-height:1.45;
color:var(--vibeui-nativeselect-002-muted);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="nativeselect-002"] *{animation:none!important;transition:none!important}}
`
/**
* Нативный select с разделами на <optgroup>: заголовки групп рисует и
* произносит сама система. Один файл, ноль зависимостей.
*/
export function Nativeselect002({
label = "Куда отгружаем",
hint = "Внутри разделов адреса отсортированы по загрузке.",
groups = [
{ label: "Склады", options: ["Основной, Химки", "Резервный, Домодедово"] },
{ label: "Офисы", options: ["Основной, Тверская", "Филиал, Казань"] },
{ label: "Партнёры", options: ["Пункт выдачи «Восток»", "Терминал СДЭК"] },
],
accent,
className,
style,
...props
}: Nativeselect002Props) {
const id = useId()
const hintId = `${id}-hint`
const palette = {
...(accent ? { "--vibeui-nativeselect-002-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-nativeselect-002" precedence="medium">
{STYLES}
</style>
<div
data-vibeui-block="nativeselect-002"
className={className}
style={palette}
>
<label htmlFor={id}>{label}</label>
<div data-part="field">
<select
{...props}
id={id}
name="destination"
aria-describedby={hintId}
>
{groups.map((group) => (
<optgroup key={group.label} label={group.label}>
{group.options.map((option) => (
<option key={option} value={option}>
{option}
</option>
))}
</optgroup>
))}
</select>
<span data-part="arrow" aria-hidden="true" />
</div>
<p data-part="hint" id={hintId}>
{hint}
</p>
</div>
</>
)
}