UNPKG

@talend/react-components

Version:
48 lines 2.08 kB
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } import { Component } from 'react'; import PropTypes from 'prop-types'; import { omit } from "lodash"; import { jsx as _jsx } from "react/jsx-runtime"; /** * This component handles some specific cases like when we click in the datalist * We loose the focus on the datalist field but we don't want to close the suggestions * until we click outside of the component * @example Here, the resetSuggestions function contains the code we can use in a classic "blur" <FocusManager onFocusOut={this.resetSuggestions}> <Typeahead /> </FocusManager> */ export default class FocusManager extends Component { constructor(...args) { super(...args); _defineProperty(this, "onFocus", event => { clearTimeout(this.timeout); if (this.props.onFocusIn) { this.props.onFocusIn(event); } }); _defineProperty(this, "onBlur", event => { if (this.props.onFocusOut) { event.persist(); this.timeout = setTimeout(() => this.props.onFocusOut(event)); } }); } render() { return /*#__PURE__*/_jsx("div", { ...omit(this.props, ['onFocusOut', 'onFocusIn', 'divRef']), ref: this.props.divRef, tabIndex: -1, onBlur: this.onBlur, onFocus: this.onFocus }); } } _defineProperty(FocusManager, "propTypes", { onFocusOut: PropTypes.func, onFocusIn: PropTypes.func, divRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func]) }); //# sourceMappingURL=FocusManager.component.js.map