Skip to content

Commit 211f982

Browse files
committed
chore: clean up
1 parent 1faca1f commit 211f982

File tree

3 files changed

+7
-49
lines changed

3 files changed

+7
-49
lines changed

src/BaseSelect/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,8 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
919919
// Style
920920
prefixCls={prefixCls}
921921
className={mergedClassName}
922+
// Focus state
923+
focused={focused}
922924
// UI
923925
prefix={prefix}
924926
suffix={suffix}

src/SelectInput/Content/MultipleContent.tsx

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,13 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function M
3535
maxTagTextLength,
3636
maxTagCount,
3737
tagRender: tagRenderFromContext,
38+
focused,
3839
} = useSelectInputContext();
39-
const { disabled, showSearch, open, toggleOpen } = useBaseProps();
40-
41-
const measureRef = React.useRef<HTMLSpanElement>(null);
42-
const [inputWidth, setInputWidth] = useState(0);
43-
const [focused, setFocused] = useState(false);
40+
const { disabled, showSearch, triggerOpen, toggleOpen } = useBaseProps();
4441

4542
// ===================== Search ======================
4643
const inputValue = showSearch ? searchValue : '';
47-
const inputEditable: boolean = showSearch && (open || focused);
48-
49-
// We measure width and set to the input immediately
50-
useLayoutEffect(() => {
51-
if (measureRef.current) {
52-
setInputWidth(measureRef.current.scrollWidth);
53-
}
54-
}, [inputValue]);
44+
const inputEditable: boolean = showSearch && (triggerOpen || focused);
5545

5646
// Props from context with safe defaults
5747
const removeIcon: RenderNode = removeIconFromContext ?? '×';
@@ -111,7 +101,7 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function M
111101
) => {
112102
const onMouseDown = (e: React.MouseEvent) => {
113103
onPreventMouseDown(e);
114-
onToggleOpen(!open);
104+
onToggleOpen(!triggerOpen);
115105
};
116106
return (
117107
<span onMouseDown={onMouseDown}>
@@ -128,34 +118,6 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function M
128118
);
129119
};
130120

131-
// ======================= Input ========================
132-
// >>> Input Node
133-
const inputNode = (
134-
<div
135-
className={`${prefixCls}-search`}
136-
style={{ width: inputWidth }}
137-
onFocus={() => {
138-
setFocused(true);
139-
}}
140-
onBlur={() => {
141-
setFocused(false);
142-
}}
143-
>
144-
<Input
145-
ref={ref}
146-
disabled={disabled}
147-
readOnly={!inputEditable}
148-
{...inputProps}
149-
value={inputValue || ''}
150-
/>
151-
152-
{/* Measure Node */}
153-
<span ref={measureRef} className={`${prefixCls}-search-mirror`} aria-hidden>
154-
{inputValue}&nbsp;
155-
</span>
156-
</div>
157-
);
158-
159121
// ====================== Overflow ======================
160122
const renderItem = (valueItem: DisplayValueType, info: { index: number }) => {
161123
const { disabled: itemDisabled, label, value } = valueItem;
@@ -207,13 +169,6 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function M
207169
};
208170

209171
// ======================= Render =======================
210-
// return (
211-
// // <div className={`${prefixCls}-content`}>
212-
// {/* <Input ref={ref} {...inputProps} value={searchValue} /> */}
213-
214-
// // </div>
215-
// );
216-
217172
return (
218173
<Overflow
219174
prefixCls={`${prefixCls}-content`}

src/SelectInput/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface SelectInputProps extends Omit<React.HTMLAttributes<HTMLDivEleme
3232
// Add other props that need to be passed through
3333
className?: string;
3434
style?: React.CSSProperties;
35+
focused?: boolean;
3536
[key: string]: any;
3637
}
3738
import useBaseProps from '../hooks/useBaseProps';

0 commit comments

Comments
 (0)