Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs][material-ui][joy-ui][Autocomplete] Fix Hint demo (@ManthanGajjar) #43039

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading