Skip to content

Commit

Permalink
inactive file selector
Browse files Browse the repository at this point in the history
resolves #1532
  • Loading branch information
Fred Lefévère-Laoide authored and Fred Lefévère-Laoide committed Jul 16, 2024
1 parent 56903f6 commit 180fb69
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe("FileSelector Component", () => {
const { getByText } = render(<FileSelector label="val" active={false} />);
const elt = getByText("val");
expect(elt).toHaveClass("Mui-disabled");
expect(elt.parentElement?.parentElement?.querySelector("input")).toBeDisabled();
});
it("is enabled by default", async () => {
const { getByText } = render(<FileSelector label="val" />);
Expand Down
41 changes: 22 additions & 19 deletions frontend/taipy-gui/src/components/Taipy/FileSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,25 @@ const FileSelector = (props: FileSelectorProps) => {
onAction && dispatch(createSendActionNameAction(id, module, onAction));
notify &&
dispatch(
createAlertAction({ atype: "success", message: value, system: false, duration: 3000 }),
createAlertAction({ atype: "success", message: value, system: false, duration: 3000 })
);
},
(reason) => {
setUpload(false);
notify &&
dispatch(
createAlertAction({ atype: "error", message: reason, system: false, duration: 3000 }),
createAlertAction({ atype: "error", message: reason, system: false, duration: 3000 })
);
},
}
);
}
},
[state.id, id, onAction, notify, updateVarName, dispatch, module],
[state.id, id, onAction, notify, updateVarName, dispatch, module]
);

const handleChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => handleFiles(e.target.files, e),
[handleFiles],
[handleFiles]
);

const handleDrop = useCallback(
Expand All @@ -105,7 +105,7 @@ const FileSelector = (props: FileSelectorProps) => {
setDropSx(defaultSx);
handleFiles(e.dataTransfer?.files, e);
},
[handleFiles],
[handleFiles]
);

const handleDragLeave = useCallback(() => {
Expand All @@ -118,12 +118,12 @@ const FileSelector = (props: FileSelectorProps) => {
console.log(evt);
const target = evt.currentTarget as HTMLElement;
setDropSx((sx) =>
sx.minWidth === defaultSx.minWidth && target ? { minWidth: target.clientWidth + "px" } : sx,
sx.minWidth === defaultSx.minWidth && target ? { minWidth: target.clientWidth + "px" } : sx
);
setDropLabel(dropMessage);
handleDragOver(evt);
},
[dropMessage],
[dropMessage]
);

useEffect(() => {
Expand Down Expand Up @@ -153,19 +153,22 @@ const FileSelector = (props: FileSelectorProps) => {
accept={extensions}
multiple={multiple}
onChange={handleChange}
disabled={!active || upload}
/>
<Tooltip title={hover || ""}>
<Button
id={id}
component="span"
aria-label="upload"
variant="outlined"
disabled={!active || upload}
sx={dropSx}
ref={butRef}
>
<UploadFile /> {dropLabel || label || defaultLabel}
</Button>
<span>
<Button
id={id}
component="span"
aria-label="upload"
variant="outlined"
disabled={!active || upload}
sx={dropSx}
ref={butRef}
>
<UploadFile /> {dropLabel || label || defaultLabel}
</Button>
</span>
</Tooltip>
{upload ? <LinearProgress value={progress} /> : null}
</label>
Expand Down

0 comments on commit 180fb69

Please sign in to comment.