You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.4 KiB
99 lines
3.4 KiB
"use strict";
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
|
|
var _react = _interopRequireDefault(require("react"));
|
|
|
|
var _pickAttrs = _interopRequireDefault(require("rc-util/lib/pickAttrs"));
|
|
|
|
var _Input = _interopRequireDefault(require("./Input"));
|
|
|
|
var SingleSelector = function SingleSelector(props) {
|
|
var inputElement = props.inputElement,
|
|
prefixCls = props.prefixCls,
|
|
id = props.id,
|
|
inputRef = props.inputRef,
|
|
disabled = props.disabled,
|
|
autoFocus = props.autoFocus,
|
|
autoComplete = props.autoComplete,
|
|
accessibilityIndex = props.accessibilityIndex,
|
|
mode = props.mode,
|
|
open = props.open,
|
|
values = props.values,
|
|
placeholder = props.placeholder,
|
|
tabIndex = props.tabIndex,
|
|
showSearch = props.showSearch,
|
|
searchValue = props.searchValue,
|
|
activeValue = props.activeValue,
|
|
onInputKeyDown = props.onInputKeyDown,
|
|
onInputMouseDown = props.onInputMouseDown,
|
|
onInputChange = props.onInputChange,
|
|
onInputPaste = props.onInputPaste,
|
|
onInputCompositionStart = props.onInputCompositionStart,
|
|
onInputCompositionEnd = props.onInputCompositionEnd;
|
|
|
|
var _React$useState = _react.default.useState(false),
|
|
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
|
|
inputChanged = _React$useState2[0],
|
|
setInputChanged = _React$useState2[1];
|
|
|
|
var combobox = mode === 'combobox';
|
|
var inputEditable = combobox || showSearch && open;
|
|
var item = values[0];
|
|
var inputValue = searchValue || '';
|
|
|
|
if (combobox && activeValue && !inputChanged) {
|
|
inputValue = activeValue;
|
|
}
|
|
|
|
_react.default.useEffect(function () {
|
|
if (combobox) {
|
|
setInputChanged(false);
|
|
}
|
|
}, [combobox, activeValue]); // Not show text when closed expect combobox mode
|
|
|
|
|
|
var hasTextInput = mode !== 'combobox' && !open ? false : !!inputValue;
|
|
var title = item && (typeof item.label === 'string' || typeof item.label === 'number') ? item.label.toString() : undefined;
|
|
return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement("span", {
|
|
className: "".concat(prefixCls, "-selection-search")
|
|
}, _react.default.createElement(_Input.default, {
|
|
ref: inputRef,
|
|
prefixCls: prefixCls,
|
|
id: id,
|
|
open: open,
|
|
inputElement: inputElement,
|
|
disabled: disabled,
|
|
autoFocus: autoFocus,
|
|
autoComplete: autoComplete,
|
|
editable: inputEditable,
|
|
accessibilityIndex: accessibilityIndex,
|
|
value: inputValue,
|
|
onKeyDown: onInputKeyDown,
|
|
onMouseDown: onInputMouseDown,
|
|
onChange: function onChange(e) {
|
|
setInputChanged(true);
|
|
onInputChange(e);
|
|
},
|
|
onPaste: onInputPaste,
|
|
onCompositionStart: onInputCompositionStart,
|
|
onCompositionEnd: onInputCompositionEnd,
|
|
tabIndex: tabIndex,
|
|
attrs: (0, _pickAttrs.default)(props, true)
|
|
})), !combobox && item && !hasTextInput && _react.default.createElement("span", {
|
|
className: "".concat(prefixCls, "-selection-item"),
|
|
title: title
|
|
}, item.label), !item && !hasTextInput && _react.default.createElement("span", {
|
|
className: "".concat(prefixCls, "-selection-placeholder")
|
|
}, placeholder));
|
|
};
|
|
|
|
var _default = SingleSelector;
|
|
exports.default = _default; |