Skip to content

Commit 1140095

Browse files
authoredJul 25, 2023
Add listbox placement demo for Select (#38130)
1 parent 35f2950 commit 1140095

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as React from 'react';
2+
import Select from '@mui/joy/Select';
3+
import Option from '@mui/joy/Option';
4+
5+
function SelectPosition() {
6+
return (
7+
<Select
8+
placeholder="Select address"
9+
sx={{ width: 240 }}
10+
slotProps={{
11+
listbox: {
12+
placement: 'bottom-start',
13+
},
14+
}}
15+
>
16+
<Option value="1">
17+
Flat 5, 24 Bhlenheiman Avenue, South Kensington, EW13 9SD
18+
</Option>
19+
<Option value="2">
20+
Flat 6, 24 Bhlenheiman Avenue, South Kensington, EW13 9SD
21+
</Option>
22+
<Option value="3">
23+
Flat 6b, 24 Bhlenheiman Avenue, South Kensington, EW13 9SD
24+
</Option>
25+
</Select>
26+
);
27+
}
28+
29+
export default SelectPosition;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as React from 'react';
2+
import Select from '@mui/joy/Select';
3+
import Option from '@mui/joy/Option';
4+
5+
function SelectPosition() {
6+
return (
7+
<Select
8+
placeholder="Select address"
9+
sx={{ width: 240 }}
10+
slotProps={{
11+
listbox: {
12+
placement: 'bottom-start',
13+
},
14+
}}
15+
>
16+
<Option value="1">
17+
Flat 5, 24 Bhlenheiman Avenue, South Kensington, EW13 9SD
18+
</Option>
19+
<Option value="2">
20+
Flat 6, 24 Bhlenheiman Avenue, South Kensington, EW13 9SD
21+
</Option>
22+
<Option value="3">
23+
Flat 6b, 24 Bhlenheiman Avenue, South Kensington, EW13 9SD
24+
</Option>
25+
</Select>
26+
);
27+
}
28+
29+
export default SelectPosition;

‎docs/data/joy/components/select/select.md

+6
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ To control the placement of the listbox, use `placement`:
132132
133133
:::
134134
135+
#### Placement
136+
137+
To align `listbox` position to `Select` while displaying long options, use `slotProps` prop to position listbox slot:
138+
139+
{{"demo": "SelectPosition.js"}}
140+
135141
#### Controlling the open state
136142
137143
You can control the open state of the select with the `listboxOpen` prop. Alternatively, it is also possible to set the initial (uncontrolled) open state of the component with the `defaultListboxOpen` prop.

0 commit comments

Comments
 (0)
Please sign in to comment.