material-react-table 0.38.1 → 0.38.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1781,33 +1781,43 @@ const MRT_EditCellTextField = ({ cell, showLabel, table, }) => {
1781
1781
  })
1782
1782
  : columnDef.muiTableBodyCellEditTextFieldProps;
1783
1783
  const textFieldProps = Object.assign(Object.assign({}, mTableBodyCellEditTextFieldProps), mcTableBodyCellEditTextFieldProps);
1784
+ const saveRow = (newValue) => {
1785
+ if (editingRow) {
1786
+ setEditingRow(Object.assign(Object.assign({}, editingRow), { _valuesCache: Object.assign(Object.assign({}, editingRow._valuesCache), { [column.id]: newValue }) }));
1787
+ }
1788
+ };
1784
1789
  const handleChange = (event) => {
1785
1790
  var _a;
1786
1791
  (_a = textFieldProps.onChange) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, event);
1787
1792
  setValue(event.target.value);
1788
- if ((textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.select) && editingRow) {
1789
- setEditingRow(Object.assign(Object.assign({}, editingRow), { _valuesCache: Object.assign(Object.assign({}, editingRow._valuesCache), { [column.id]: event.target.value }) }));
1793
+ if (textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.select) {
1794
+ saveRow(event.target.value);
1790
1795
  }
1791
1796
  };
1792
1797
  const handleBlur = (event) => {
1793
1798
  var _a;
1794
1799
  (_a = textFieldProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, event);
1795
- if (editingRow) {
1796
- setEditingRow(Object.assign(Object.assign({}, editingRow), { _valuesCache: Object.assign(Object.assign({}, editingRow._valuesCache), { [column.id]: value }) }));
1797
- }
1800
+ saveRow(value);
1798
1801
  setEditingCell(null);
1799
1802
  };
1803
+ const handleEnterKeyDown = (event) => {
1804
+ var _a, _b;
1805
+ (_a = textFieldProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, event);
1806
+ if (event.key === 'Enter') {
1807
+ (_b = editInputRefs.current[column.id]) === null || _b === void 0 ? void 0 : _b.blur();
1808
+ }
1809
+ };
1800
1810
  if (columnDef.Edit) {
1801
1811
  return React__default["default"].createElement(React__default["default"].Fragment, null, (_a = columnDef.Edit) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, row, table }));
1802
1812
  }
1803
- return (React__default["default"].createElement(material.TextField, Object.assign({ disabled: columnDef.enableEditing === false, fullWidth: true, label: showLabel ? column.columnDef.header : undefined, margin: "none", name: column.id, onClick: (e) => e.stopPropagation(), placeholder: columnDef.header, value: value, variant: "standard" }, textFieldProps, { inputRef: (inputRef) => {
1813
+ return (React__default["default"].createElement(material.TextField, Object.assign({ disabled: columnDef.enableEditing === false, fullWidth: true, inputRef: (inputRef) => {
1804
1814
  if (inputRef) {
1805
1815
  editInputRefs.current[column.id] = inputRef;
1806
1816
  if (textFieldProps.inputRef) {
1807
1817
  textFieldProps.inputRef = inputRef;
1808
1818
  }
1809
1819
  }
1810
- }, onBlur: handleBlur, onChange: handleChange })));
1820
+ }, label: showLabel ? column.columnDef.header : undefined, margin: "none", name: column.id, onClick: (e) => e.stopPropagation(), placeholder: columnDef.header, value: value, variant: "standard" }, textFieldProps, { onBlur: handleBlur, onChange: handleChange, onKeyDown: handleEnterKeyDown })));
1811
1821
  };
1812
1822
 
1813
1823
  const MRT_CopyButton = ({ cell, children, table, }) => {