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

feat: adaptative suggester width #223

Merged
merged 4 commits into from
Jan 10, 2025
Merged
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
28 changes: 18 additions & 10 deletions src/Suggester.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import { useQuestionId } from "./Question";
import type { SuggesterOptionType } from "@inseefr/lunatic/components/Suggester/SuggesterType";
import TextareaAutosize from "@mui/material/TextareaAutosize";
import { fr } from "@codegouvfr/react-dsfr";
import { Paper, Popper, styled } from "@mui/material";

const CustomPaper = styled(Paper)(() => ({
zIndex: 1,
backgroundColor: "white",
}));

const CustomPopper = styled(Popper)(() => ({
minWidth: "fit-content",
}));

export const Suggester: LunaticSlotComponents["Suggester"] = props => {
const {
Expand Down Expand Up @@ -36,7 +46,6 @@ export const Suggester: LunaticSlotComponents["Suggester"] = props => {
return (
<Autocomplete
id={id}
disablePortal
value={(value[0] ?? null) as SuggesterOptionType} //To remove when https://github.com/InseeFr/Lunatic/pull/1067 merged
inputValue={inputValue}
isOptionEqualToValue={(a, b) => a.id === b.id}
Expand All @@ -59,6 +68,13 @@ export const Suggester: LunaticSlotComponents["Suggester"] = props => {
onSearch(v);
}
}}
renderOption={(props, option) => (
<li {...props} title={option.label}>
{option.label}
</li>
)}
PaperComponent={({ children }) => <CustomPaper elevation={3}>{children}</CustomPaper>}
PopperComponent={props => <CustomPopper {...props} placement="bottom-start" />}
renderInput={params => {
const errorMessageId = `${params.id}-desc-error`; //we use the same convention as react-dsfr
return (
Expand Down Expand Up @@ -112,15 +128,7 @@ export const Suggester: LunaticSlotComponents["Suggester"] = props => {
minHeight: 0, //Override dsfr minHeight
resize: "none",
}}
>
<Button
iconId="ri-close-line"
priority="secondary"
onClick={onClear}
title="vider le champ"
disabled={inputValue === ""}
/>
</TextareaAutosize>
/>
<Button
iconId="ri-close-line"
priority="secondary"
Expand Down
Loading