Input.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
  3. var _excluded = ["prefixCls", "id", "inputElement", "autoFocus", "autoComplete", "editable", "activeDescendantId", "value", "open", "attrs"];
  4. import * as React from 'react';
  5. import classNames from 'classnames';
  6. import { composeRef } from "rc-util/es/ref";
  7. import { warning } from "rc-util/es/warning";
  8. import composeProps from "rc-util/es/composeProps";
  9. var Input = function Input(props, ref) {
  10. var prefixCls = props.prefixCls,
  11. id = props.id,
  12. inputElement = props.inputElement,
  13. autoFocus = props.autoFocus,
  14. autoComplete = props.autoComplete,
  15. editable = props.editable,
  16. activeDescendantId = props.activeDescendantId,
  17. value = props.value,
  18. open = props.open,
  19. attrs = props.attrs,
  20. restProps = _objectWithoutProperties(props, _excluded);
  21. var inputNode = inputElement || /*#__PURE__*/React.createElement("input", null);
  22. var _inputNode = inputNode,
  23. originRef = _inputNode.ref,
  24. originProps = _inputNode.props;
  25. warning(!('maxLength' in inputNode.props), "Passing 'maxLength' to input element directly may not work because input in BaseSelect is controlled.");
  26. inputNode = /*#__PURE__*/React.cloneElement(inputNode, _objectSpread(_objectSpread(_objectSpread({
  27. type: 'search'
  28. }, composeProps(restProps, originProps, true)), {}, {
  29. // Override over origin props
  30. id: id,
  31. ref: composeRef(ref, originRef),
  32. autoComplete: autoComplete || 'off',
  33. autoFocus: autoFocus,
  34. className: classNames("".concat(prefixCls, "-selection-search-input"), originProps === null || originProps === void 0 ? void 0 : originProps.className),
  35. role: 'combobox',
  36. 'aria-expanded': open || false,
  37. 'aria-haspopup': 'listbox',
  38. 'aria-owns': "".concat(id, "_list"),
  39. 'aria-autocomplete': 'list',
  40. 'aria-controls': "".concat(id, "_list"),
  41. 'aria-activedescendant': open ? activeDescendantId : undefined
  42. }, attrs), {}, {
  43. value: editable ? value : '',
  44. readOnly: !editable,
  45. unselectable: !editable ? 'on' : null,
  46. style: _objectSpread(_objectSpread({}, originProps.style), {}, {
  47. opacity: editable ? null : 0
  48. })
  49. }));
  50. return inputNode;
  51. };
  52. var RefInput = /*#__PURE__*/React.forwardRef(Input);
  53. if (process.env.NODE_ENV !== 'production') {
  54. RefInput.displayName = 'Input';
  55. }
  56. export default RefInput;