-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1463 from cityofaustin/mateo/18178_dategridpro
Project Team DataGridPro migration
- Loading branch information
Showing
11 changed files
with
798 additions
and
416 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
moped-editor/src/components/DataGridPro/DataGridTextField.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from "react"; | ||
import { TextField } from "@mui/material"; | ||
import { useGridApiContext } from "@mui/x-data-grid-pro"; | ||
|
||
/** | ||
* @param {Integer} id - Data Grid row id | ||
* @param {String} value - field value | ||
* @param {String} field - name of field | ||
* @param {Boolean} hasFocus - does this field have focus | ||
* @param {String} helperText - optional helper text | ||
* @param {Boolean} error - toggles error style in textfield | ||
* @return {JSX.Element} | ||
*/ | ||
const DataGridTextField = ({ | ||
id, | ||
value, | ||
field, | ||
hasFocus, | ||
helperText, | ||
error, | ||
multiline = false, | ||
}) => { | ||
const apiRef = useGridApiContext(); | ||
const ref = React.useRef(null); | ||
|
||
React.useEffect(() => { | ||
if (hasFocus) { | ||
ref.current.focus(); | ||
} | ||
}, [hasFocus]); | ||
|
||
const handleChange = (event, newValue) => { | ||
const { value: inputValue } = event.target; | ||
|
||
apiRef.current.setEditCellValue({ | ||
id, | ||
field, | ||
value: inputValue, | ||
}); | ||
}; | ||
|
||
return ( | ||
<TextField | ||
variant="standard" | ||
style={{ width: "inherit", paddingTop: "inherit" }} | ||
id={field} | ||
inputRef={ref} | ||
name={field} | ||
type="text" | ||
value={value ?? ""} | ||
onChange={handleChange} | ||
helperText={!!helperText && helperText} | ||
error={error} | ||
multiline={multiline} | ||
/> | ||
); | ||
}; | ||
|
||
export default DataGridTextField; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.