Skip to content

Commit

Permalink
chore: back of dropdownStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Dec 21, 2021
1 parent 10eacf7 commit 6c0a047
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ const Demo = () => {
</label>
<Cascader
style={{ width: 200 }}
options={addressOptions}
// options={addressOptions}
onChange={onChange}
checkable={multiple}
allowClear
// defaultValue={multiple ? [defaultValue] : defaultValue}
defaultValue={[['not', 'yet'], ['exist']]}
showSearch
// showSearch={{ limit: 1 }}
// open
open
// direction="rtl"
// searchValue="福a"
// changeOnSelect
Expand Down
18 changes: 15 additions & 3 deletions src/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
mergedSearchValue,
mergedOptions,
mergedFieldNames,
prefixCls,
dropdownPrefixCls || prefixCls,
searchConfig,
changeOnSelect,
);
Expand Down Expand Up @@ -460,6 +460,18 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
// ==============================================================
// == Render ==
// ==============================================================
const emptyOptions = !(mergedSearchValue ? searchOptions : mergedOptions).length;

const dropdownStyle: React.CSSProperties =
// Search to match width
(mergedSearchValue && searchConfig.matchInputWidth) ||
// Empty keep the width
emptyOptions
? {}
: {
minWidth: 'auto',
};

return (
<CascaderContext.Provider value={cascaderContext}>
<BaseSelect
Expand All @@ -469,7 +481,7 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
id={mergedId}
prefixCls={prefixCls}
dropdownMatchSelectWidth={false}
dropdownStyle={{ minWidth: 'auto' }}
dropdownStyle={dropdownStyle}
// Value
displayValues={displayValues}
onDisplayValuesChange={onDisplayValuesChange}
Expand All @@ -480,7 +492,7 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
showSearch={mergedShowSearch}
// Options
OptionList={OptionList}
emptyOptions={!(mergedSearchValue ? searchOptions : mergedOptions).length}
emptyOptions={emptyOptions}
// Open
open={mergedOpen}
dropdownClassName={mergedDropdownClassName}
Expand Down

1 comment on commit 6c0a047

@vercel
Copy link

@vercel vercel bot commented on 6c0a047 Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.