Skip to content

Commit

Permalink
[docs][material-ui][joy-ui][Autocomplete] Fix Hint demo (@ManthanGa…
Browse files Browse the repository at this point in the history
…jjar) (#43039)

Co-authored-by: Manthan Gajjar <31969308+ManthanGajjar@users.noreply.github.com>
Co-authored-by: ZeeshanTamboli <zeeshan.tamboli@gmail.com>
  • Loading branch information
3 people authored Jul 23, 2024
1 parent 22ff84d commit 4bd8176
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 29 deletions.
14 changes: 12 additions & 2 deletions docs/data/joy/components/autocomplete/AutocompleteHint.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ const StyledDiv = styled('div')({
function Wrapper({ children, hint, ...props }) {
return (
<StyledDiv {...props}>
<Typography sx={{ position: 'absolute', opacity: 0.6 }}>{hint}</Typography>
<Typography
sx={{
position: 'absolute',
opacity: 0.6,
overflow: 'hidden', // Hide overflow
whiteSpace: 'nowrap', // Prevent text wrapping
maxWidth: '100%', // Ensure the hint doesn't exceed container width
}}
>
{hint}
</Typography>
{children}
</StyledDiv>
);
Expand Down Expand Up @@ -53,7 +63,7 @@ export default function AutocompleteHint() {
}
}
}}
onBlur={() => {
onClose={() => {
hint.current = '';
}}
inputValue={inputValue}
Expand Down
14 changes: 12 additions & 2 deletions docs/data/joy/components/autocomplete/AutocompleteHint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ type WrapperProps = {
function Wrapper({ children, hint, ...props }: WrapperProps) {
return (
<StyledDiv {...props}>
<Typography sx={{ position: 'absolute', opacity: 0.6 }}>{hint}</Typography>
<Typography
sx={{
position: 'absolute',
opacity: 0.6,
overflow: 'hidden', // Hide overflow
whiteSpace: 'nowrap', // Prevent text wrapping
maxWidth: '100%', // Ensure the hint doesn't exceed container width
}}
>
{hint}
</Typography>
{children}
</StyledDiv>
);
Expand Down Expand Up @@ -52,7 +62,7 @@ export default function AutocompleteHint() {
}
}
}}
onBlur={() => {
onClose={() => {
hint.current = '';
}}
inputValue={inputValue}
Expand Down
25 changes: 13 additions & 12 deletions docs/data/material/components/autocomplete/AutocompleteHint.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,30 @@ export default function AutocompleteHint() {
}
}
}}
onBlur={() => {
onClose={() => {
hint.current = '';
}}
onChange={(event, newValue) => {
setInputValue(newValue && newValue.label ? newValue.label : '');
}}
disablePortal
inputValue={inputValue}
filterOptions={(options, state) => {
const displayOptions = options.filter((option) =>
option.label
.toLowerCase()
.trim()
.includes(state.inputValue.toLowerCase().trim()),
);

return displayOptions;
}}
id="combo-box-hint-demo"
options={top100Films}
sx={{ width: 300 }}
renderInput={(params) => {
return (
<Box sx={{ position: 'relative' }}>
<Typography
sx={{ position: 'absolute', opacity: 0.5, left: 14, top: 16 }}
sx={{
position: 'absolute',
opacity: 0.5,
left: 14,
top: 16,
overflow: 'hidden',
whiteSpace: 'nowrap',
width: 'calc(100% - 75px)', // Adjust based on padding of TextField
}}
>
{hint.current}
</Typography>
Expand Down
25 changes: 13 additions & 12 deletions docs/data/material/components/autocomplete/AutocompleteHint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,30 @@ export default function AutocompleteHint() {
}
}
}}
onBlur={() => {
onClose={() => {
hint.current = '';
}}
onChange={(event, newValue) => {
setInputValue(newValue && newValue.label ? newValue.label : '');
}}
disablePortal
inputValue={inputValue}
filterOptions={(options, state) => {
const displayOptions = options.filter((option) =>
option.label
.toLowerCase()
.trim()
.includes(state.inputValue.toLowerCase().trim()),
);

return displayOptions;
}}
id="combo-box-hint-demo"
options={top100Films}
sx={{ width: 300 }}
renderInput={(params) => {
return (
<Box sx={{ position: 'relative' }}>
<Typography
sx={{ position: 'absolute', opacity: 0.5, left: 14, top: 16 }}
sx={{
position: 'absolute',
opacity: 0.5,
left: 14,
top: 16,
overflow: 'hidden',
whiteSpace: 'nowrap',
width: 'calc(100% - 75px)', // Adjust based on padding of TextField
}}
>
{hint.current}
</Typography>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/autocomplete/autocomplete.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Head to the [Customized hook](#customized-hook) section for a customization exam

### Hint

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

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

Expand Down

0 comments on commit 4bd8176

Please sign in to comment.