Skip to content

Commit 8b9b8d5

Browse files
ManthanGajjarZeeshanTamboli
authored andcommitted
[docs][material-ui][joy-ui][Autocomplete] Fix Hint demo (#42990)
Co-authored-by: ZeeshanTamboli <[email protected]>
1 parent 22ff84d commit 8b9b8d5

File tree

5 files changed

+51
-29
lines changed

5 files changed

+51
-29
lines changed

docs/data/joy/components/autocomplete/AutocompleteHint.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ const StyledDiv = styled('div')({
1515
function Wrapper({ children, hint, ...props }) {
1616
return (
1717
<StyledDiv {...props}>
18-
<Typography sx={{ position: 'absolute', opacity: 0.6 }}>{hint}</Typography>
18+
<Typography
19+
sx={{
20+
position: 'absolute',
21+
opacity: 0.6,
22+
overflow: 'hidden', // Hide overflow
23+
whiteSpace: 'nowrap', // Prevent text wrapping
24+
maxWidth: '100%', // Ensure the hint doesn't exceed container width
25+
}}
26+
>
27+
{hint}
28+
</Typography>
1929
{children}
2030
</StyledDiv>
2131
);
@@ -53,7 +63,7 @@ export default function AutocompleteHint() {
5363
}
5464
}
5565
}}
56-
onBlur={() => {
66+
onClose={() => {
5767
hint.current = '';
5868
}}
5969
inputValue={inputValue}

docs/data/joy/components/autocomplete/AutocompleteHint.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@ type WrapperProps = {
1919
function Wrapper({ children, hint, ...props }: WrapperProps) {
2020
return (
2121
<StyledDiv {...props}>
22-
<Typography sx={{ position: 'absolute', opacity: 0.6 }}>{hint}</Typography>
22+
<Typography
23+
sx={{
24+
position: 'absolute',
25+
opacity: 0.6,
26+
overflow: 'hidden', // Hide overflow
27+
whiteSpace: 'nowrap', // Prevent text wrapping
28+
maxWidth: '100%', // Ensure the hint doesn't exceed container width
29+
}}
30+
>
31+
{hint}
32+
</Typography>
2333
{children}
2434
</StyledDiv>
2535
);
@@ -52,7 +62,7 @@ export default function AutocompleteHint() {
5262
}
5363
}
5464
}}
55-
onBlur={() => {
65+
onClose={() => {
5666
hint.current = '';
5767
}}
5868
inputValue={inputValue}

docs/data/material/components/autocomplete/AutocompleteHint.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,30 @@ export default function AutocompleteHint() {
1616
}
1717
}
1818
}}
19-
onBlur={() => {
19+
onClose={() => {
2020
hint.current = '';
2121
}}
22+
onChange={(event, newValue) => {
23+
setInputValue(newValue && newValue.label ? newValue.label : '');
24+
}}
2225
disablePortal
2326
inputValue={inputValue}
24-
filterOptions={(options, state) => {
25-
const displayOptions = options.filter((option) =>
26-
option.label
27-
.toLowerCase()
28-
.trim()
29-
.includes(state.inputValue.toLowerCase().trim()),
30-
);
31-
32-
return displayOptions;
33-
}}
3427
id="combo-box-hint-demo"
3528
options={top100Films}
3629
sx={{ width: 300 }}
3730
renderInput={(params) => {
3831
return (
3932
<Box sx={{ position: 'relative' }}>
4033
<Typography
41-
sx={{ position: 'absolute', opacity: 0.5, left: 14, top: 16 }}
34+
sx={{
35+
position: 'absolute',
36+
opacity: 0.5,
37+
left: 14,
38+
top: 16,
39+
overflow: 'hidden',
40+
whiteSpace: 'nowrap',
41+
width: 'calc(100% - 75px)', // Adjust based on padding of TextField
42+
}}
4243
>
4344
{hint.current}
4445
</Typography>

docs/data/material/components/autocomplete/AutocompleteHint.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,30 @@ export default function AutocompleteHint() {
1616
}
1717
}
1818
}}
19-
onBlur={() => {
19+
onClose={() => {
2020
hint.current = '';
2121
}}
22+
onChange={(event, newValue) => {
23+
setInputValue(newValue && newValue.label ? newValue.label : '');
24+
}}
2225
disablePortal
2326
inputValue={inputValue}
24-
filterOptions={(options, state) => {
25-
const displayOptions = options.filter((option) =>
26-
option.label
27-
.toLowerCase()
28-
.trim()
29-
.includes(state.inputValue.toLowerCase().trim()),
30-
);
31-
32-
return displayOptions;
33-
}}
3427
id="combo-box-hint-demo"
3528
options={top100Films}
3629
sx={{ width: 300 }}
3730
renderInput={(params) => {
3831
return (
3932
<Box sx={{ position: 'relative' }}>
4033
<Typography
41-
sx={{ position: 'absolute', opacity: 0.5, left: 14, top: 16 }}
34+
sx={{
35+
position: 'absolute',
36+
opacity: 0.5,
37+
left: 14,
38+
top: 16,
39+
overflow: 'hidden',
40+
whiteSpace: 'nowrap',
41+
width: 'calc(100% - 75px)', // Adjust based on padding of TextField
42+
}}
4243
>
4344
{hint.current}
4445
</Typography>

docs/data/material/components/autocomplete/autocomplete.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ Head to the [Customized hook](#customized-hook) section for a customization exam
282282

283283
### Hint
284284

285-
The following demo shows how to add a hint feature to the Autocomplete using the `renderInput` and `filterOptions` props:
285+
The following demo shows how to add a hint feature to the Autocomplete:
286286

287287
{{"demo": "AutocompleteHint.js"}}
288288

0 commit comments

Comments
 (0)