CUSTOMIZE FILE DOWNLOAD BUTTON USING MUI COMPONENT
Here we need to use three MUI components to customize the file download button
Text field of type =’file’
Entrance label which will be attached to the Textfield download button using its “id” in htmlFor accessories.
Next we need to put the Button component inside the Entrance label and keep the display of Text field like none so that the default download button can be hidden and we can show the custom download button.
There is one important thing to note here: we need to use the component accessory in the Button component and must retain its value such that scope to make this custom button work as download button.
We will use the handleFileUpload function to get the downloaded file and put logic into it to handle the downloaded file.
import TextField from “@mui/material/TextField”; import InputLabel from “@mui/material/InputLabel”; import button from “@mui/material/Button”; const UploadButton = () => { const handleFileUpload = (event) => { console.log(event.target.files[0]); } ; return(<>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
import Text field Since “@mui/material/TextField”; import Entrance label Since “@mui/material/InputLabel”; import Button Since “@mui/material/Button”; const Download button = () => { const handleFileUpload = (event) => { console.save(event.target.files[0]); }; back ( <> <Entrance label htmlFor=“download”> <Button variant=“describe” component=“scope”> Download Deposit </Button> nputLabel> <Text field type=“deposit” sex={{ display: “none” }} identifier=“download” onChange={handleFileUpload} /> </> ); }; export default Download button; |