apps/mantine.dev/src/pages/core/native-select.mdx
import { NativeSelectDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';
export default Layout(MDX_DATA.NativeSelect);
Set loading prop to display a loading indicator. By default, the loader is displayed on the right side of the input.
You can change the position with the loadingPosition prop to 'left' or 'right'. This is useful for async operations like API calls, searches, or validations:
import { useState } from 'react';
import { NativeSelect } from '@mantine/core';
function Demo() {
const [value, setValue] = useState('');
return (
<NativeSelect
value={value}
onChange={(event) => setValue(event.currentTarget.value)}
data={['React', 'Angular', 'Svelte', 'Vue']}
/>
);
}
NativeSelect can be used with uncontrolled forms the same way as a native select element.
Set the name attribute to include native select value in FormData object on form submission.
To control the initial value in uncontrolled forms, use the defaultValue prop.
Example usage of uncontrolled NativeSelect with FormData:
import { NativeSelect } from '@mantine/core';
function Demo() {
return (
<form
onSubmit={(event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
console.log('Select value:', formData.get('framework'));
}}
>
<NativeSelect
label="Select a framework"
name="framework"
data={['React', 'Angular', 'Svelte', 'Vue']}
defaultValue="React"
/>
<button type="submit">Submit</button>
</form>
);
}
NativeSelect allows passing options in two ways:
data prop arraychildren prop with option componentsNote that if children is used, the data will be ignored.
The data prop accepts values in one of the following formats:
import { NativeSelect } from '@mantine/core';
function Demo() {
return (
<NativeSelect data={['React', 'Angular', 'Svelte', 'Vue']} />
);
}
label, value and disabled keys:import { NativeSelect } from '@mantine/core';
function Demo() {
return (
<NativeSelect
data={[
{ label: 'React', value: 'react' },
{ label: 'Angular', value: 'angular' },
{ label: 'Svelte', value: 'svelte', disabled: true },
{ label: 'Vue', value: 'vue' },
]}
/>
);
}
import { NativeSelect } from '@mantine/core';
function Demo() {
return (
<NativeSelect
data={[
{
group: 'Frontend libraries',
items: ['React', 'Angular', 'Svelte', 'Vue'],
},
{
group: 'Backend libraries',
items: ['Express', 'Koa', 'Django'],
},
]}
/>
);
}
import { NativeSelect } from '@mantine/core';
function Demo() {
return (
<NativeSelect
data={[
{
group: 'Frontend libraries',
items: [
{ label: 'React', value: 'react' },
{ label: 'Angular', value: 'angular' },
{ label: 'Vue', value: 'vue', disabled: true },
],
},
{
group: 'Backend libraries',
items: [
{ label: 'Express', value: 'express' },
{ label: 'Koa', value: 'koa' },
{ label: 'Django', value: 'django' },
],
},
]}
/>
);
}
Example of the data prop with an array of grouped options:
To add options with the children prop, use option elements to add options and optgroup
elements to group them:
Use hr tags to add dividers between options: