Skip to content

Commit 5f84c83

Browse files
Fix Selector Height for Radio/Check Mode (#2425)
* 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]>
1 parent 402881b commit 5f84c83

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

frontend/taipy-gui/src/components/Taipy/Selector.spec.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ describe("Selector Component", () => {
328328
await userEvent.click(elt);
329329
expect(elt.parentElement?.querySelector("span.Mui-checked")).not.toBeNull();
330330
});
331+
it("sets the correct height for the radio mode", async () => {
332+
const height = "200px";
333+
const { getByRole } = render(<Selector lov={lov} mode="radio" height={height} />);
334+
const selector = getByRole("radiogroup");
335+
const style = window.getComputedStyle(selector);
336+
expect(style.maxHeight).toBe(height);
337+
});
331338
});
332339

333340
describe("Selector Component check mode", () => {
@@ -366,4 +373,11 @@ describe("Selector Component", () => {
366373
expect(elt3.parentElement?.querySelector("span.Mui-checked")).not.toBeNull();
367374
});
368375
});
376+
it("sets the correct height for the check mode", async () => {
377+
const height = "200px";
378+
const { container } = render(<Selector lov={lov} mode="check" height={height} />);
379+
const selector = container.querySelector(".MuiFormGroup-root");
380+
const style = window.getComputedStyle(selector!);
381+
expect(style.maxHeight).toBe(height);
382+
});
369383
});

frontend/taipy-gui/src/components/Taipy/Selector.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@ const Selector = (props: SelectorProps) => {
178178
}),
179179
[width]
180180
);
181+
const heightSx = useMemo(() => {
182+
if (!height) {
183+
return undefined;
184+
}
185+
return {
186+
maxHeight: height,
187+
display: 'flex',
188+
flexFlow: 'column nowrap',
189+
overflowY: "auto",
190+
};
191+
}, [height]);
192+
181193
const paperSx = useMemo(() => {
182194
let sx = paperBaseSx;
183195
if (height !== undefined) {
@@ -371,6 +383,7 @@ const Selector = (props: SelectorProps) => {
371383
value={dropdownValue}
372384
onChange={handleChange}
373385
className={getSuffixedClassNames(className, "-radio-group")}
386+
sx={heightSx}
374387
>
375388
{lovList.map((item) => (
376389
<FormControlLabel
@@ -390,7 +403,7 @@ const Selector = (props: SelectorProps) => {
390403
))}
391404
</RadioGroup>
392405
) : (
393-
<FormGroup className={getSuffixedClassNames(className, "-check-group")}>
406+
<FormGroup className={getSuffixedClassNames(className, "-check-group")} sx={heightSx}>
394407
{lovList.map((item) => (
395408
<FormControlLabel
396409
key={item.id}

0 commit comments

Comments
 (0)