@talend/react-components
Version:
Set of react components.
81 lines (80 loc) • 2.56 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _CellTitleModule = _interopRequireDefault(require("./CellTitle.module.scss"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* Title input mode.
* - It initializes the input value
* - It adds handlers on form submit, ESC (cancel) and blur (submit) events
*/class CellTitleInput extends _react.Component {
constructor(props) {
super(props);
this.onBlur = this.onBlur.bind(this);
this.onKeyUp = this.onKeyUp.bind(this);
this.onSubmit = this.onSubmit.bind(this);
}
componentDidMount() {
this.titleInput.value = this.props.cellData;
}
onKeyUp(event) {
if (event.key === 'Esc' || event.key === 'Escape') {
this.props.onEditCancel(event, this.props.rowData);
}
}
onBlur(event) {
this.onSubmit(event);
}
onSubmit(event) {
event.preventDefault();
this.props.onEditSubmit(event, {
value: this.titleInput.value,
model: this.props.rowData
});
}
render() {
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("form", {
onSubmit: this.onSubmit,
className: _CellTitleModule.default['edit-form'],
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
"aria-hidden": "true",
hidden: true,
className: "sr-only",
htmlFor: this.props.id,
children: this.props.label || 'title'
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
id: this.props.id,
ref: input => {
this.titleInput = input;
},
onBlur: this.onBlur,
onKeyUp: this.onKeyUp
// eslint-disable-next-line jsx-a11y/no-autofocus
,
autoFocus: true
})]
});
}
}
exports.default = CellTitleInput;
CellTitleInput.propTypes = {
/** The id prefix. */
id: _propTypes.default.string,
/** The input value. */
cellData: _propTypes.default.string.isRequired,
/** The cancel callback on ESC keydown. */
onEditCancel: _propTypes.default.func.isRequired,
/** The submit callback on ENTER keydown or blur. */
onEditSubmit: _propTypes.default.func.isRequired,
/** The collection item. */
rowData: _propTypes.default.object,
// eslint-disable-line react/forbid-prop-types
/** The input label. */
label: _propTypes.default.string
};
//# sourceMappingURL=CellTitleInput.component.js.map