Skip to content

Commit

Permalink
Fix Selector Height for Radio/Check Mode (#2425)
Browse files Browse the repository at this point in the history
* Use getWindowHeight to set the height and make the selector scrollable

* Fixed the behavior when height is not defined

* Add height test for check and radio mode.

* Use useMemo for the height

* Add nowrap to the styling and updated unit tests.

* Removed extra line

* Replaced single quotes with double quotes. Use undefined instead of {}

---------

Co-authored-by: Fred Lefévère-Laoide <[email protected]>
  • Loading branch information
Satoshi-Sh and FredLL-Avaiga authored Jan 27, 2025
1 parent 402881b commit 5f84c83
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
14 changes: 14 additions & 0 deletions frontend/taipy-gui/src/components/Taipy/Selector.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ describe("Selector Component", () => {
await userEvent.click(elt);
expect(elt.parentElement?.querySelector("span.Mui-checked")).not.toBeNull();
});
it("sets the correct height for the radio mode", async () => {
const height = "200px";
const { getByRole } = render(<Selector lov={lov} mode="radio" height={height} />);
const selector = getByRole("radiogroup");
const style = window.getComputedStyle(selector);
expect(style.maxHeight).toBe(height);
});
});

describe("Selector Component check mode", () => {
Expand Down Expand Up @@ -366,4 +373,11 @@ describe("Selector Component", () => {
expect(elt3.parentElement?.querySelector("span.Mui-checked")).not.toBeNull();
});
});
it("sets the correct height for the check mode", async () => {
const height = "200px";
const { container } = render(<Selector lov={lov} mode="check" height={height} />);
const selector = container.querySelector(".MuiFormGroup-root");
const style = window.getComputedStyle(selector!);
expect(style.maxHeight).toBe(height);
});
});
15 changes: 14 additions & 1 deletion frontend/taipy-gui/src/components/Taipy/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ const Selector = (props: SelectorProps) => {
}),
[width]
);
const heightSx = useMemo(() => {
if (!height) {
return undefined;
}
return {
maxHeight: height,
display: 'flex',
flexFlow: 'column nowrap',
overflowY: "auto",
};
}, [height]);

const paperSx = useMemo(() => {
let sx = paperBaseSx;
if (height !== undefined) {
Expand Down Expand Up @@ -371,6 +383,7 @@ const Selector = (props: SelectorProps) => {
value={dropdownValue}
onChange={handleChange}
className={getSuffixedClassNames(className, "-radio-group")}
sx={heightSx}
>
{lovList.map((item) => (
<FormControlLabel
Expand All @@ -390,7 +403,7 @@ const Selector = (props: SelectorProps) => {
))}
</RadioGroup>
) : (
<FormGroup className={getSuffixedClassNames(className, "-check-group")}>
<FormGroup className={getSuffixedClassNames(className, "-check-group")} sx={heightSx}>
{lovList.map((item) => (
<FormControlLabel
key={item.id}
Expand Down

0 comments on commit 5f84c83

Please sign in to comment.