Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(select): invalid custom width #649

Merged
merged 1 commit into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/components/src/components/select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ const Select = React.forwardRef<HTMLDivElement,SelectProps>((props: SelectProps,
const inputRef = useRef<HTMLInputElement>(null);
const [inputWidth, setInputWidth] = useState(2);
const inputWidthRef = useRef<HTMLDivElement>(null);

const selectRef = useRef<HTMLDivElement>(null)
const selectorRef = ref || selectRef;
const clearInput = () => {
setInput('');
};
Expand Down Expand Up @@ -424,7 +425,7 @@ const Select = React.forwardRef<HTMLDivElement,SelectProps>((props: SelectProps,
})}
aria-disabled={disabled}
style={style}
ref={ref}
ref={selectorRef}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
Expand All @@ -441,11 +442,11 @@ const Select = React.forwardRef<HTMLDivElement,SelectProps>((props: SelectProps,
</div>
);
const list = (
<div style={{ width: autoWidth ? Math.max(ref?.current?.clientWidth || 0, 160) : undefined }}>
<div style={{ width: autoWidth ? Math.max(selectorRef?.current?.clientWidth || 0, 160) : undefined }}>
{completeOptions.length > 0 ? (
<List
value={value}
width={autoWidth ? Math.max(ref?.current?.clientWidth || 0, 160) : undefined}
width={autoWidth ? Math.max(selectorRef?.current?.clientWidth || 0, 160) : undefined}
dataSource={(completeOptions as unknown) as Option[]}
onChange={onValueChange}
required={!allowDeselect}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Basics = (): React.ReactNode => {
</Radio.Group>
</div>
<div>
<Select options={optionsWithoutGroup} allowClear size={size} style={{ width: 140 }} placeholder="请选择" ref={selectRef} />
<Select options={optionsWithoutGroup} allowClear size={size} style={{ width: 190 }} placeholder="请选择" />
</div>
</>
);
Expand Down