-
-
Notifications
You must be signed in to change notification settings - Fork 144
feat: add disabled api for panel #543
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
Changes from all commits
7692626
75fdf31
3f41343
62d5c18
cb771fe
243125a
ef96118
9e13232
9201339
393749a
6610a9b
7691896
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,11 +21,27 @@ import useKeyboard from './useKeyboard'; | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export type RawOptionListProps = Pick< | ||||||||||||||||||||||||||
ReturnType<typeof useBaseProps>, | ||||||||||||||||||||||||||
'prefixCls' | 'multiple' | 'searchValue' | 'toggleOpen' | 'notFoundContent' | 'direction' | 'open' | ||||||||||||||||||||||||||
| 'prefixCls' | ||||||||||||||||||||||||||
| 'multiple' | ||||||||||||||||||||||||||
| 'searchValue' | ||||||||||||||||||||||||||
| 'toggleOpen' | ||||||||||||||||||||||||||
| 'notFoundContent' | ||||||||||||||||||||||||||
| 'direction' | ||||||||||||||||||||||||||
| 'open' | ||||||||||||||||||||||||||
| 'disabled' | ||||||||||||||||||||||||||
>; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((props, ref) => { | ||||||||||||||||||||||||||
const { prefixCls, multiple, searchValue, toggleOpen, notFoundContent, direction, open } = props; | ||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||
prefixCls, | ||||||||||||||||||||||||||
multiple, | ||||||||||||||||||||||||||
searchValue, | ||||||||||||||||||||||||||
toggleOpen, | ||||||||||||||||||||||||||
notFoundContent, | ||||||||||||||||||||||||||
direction, | ||||||||||||||||||||||||||
open, | ||||||||||||||||||||||||||
disabled, | ||||||||||||||||||||||||||
} = props; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const containerRef = React.useRef<HTMLDivElement>(null); | ||||||||||||||||||||||||||
const rtl = direction === 'rtl'; | ||||||||||||||||||||||||||
|
@@ -100,10 +116,14 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>(( | |||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const isSelectable = (option: DefaultOptionType) => { | ||||||||||||||||||||||||||
const { disabled } = option; | ||||||||||||||||||||||||||
if (disabled) { | ||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const { disabled: optionDisabled } = option; | ||||||||||||||||||||||||||
const isMergedLeaf = isLeaf(option, fieldNames); | ||||||||||||||||||||||||||
return !disabled && (isMergedLeaf || changeOnSelect || multiple); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return !optionDisabled && (isMergedLeaf || changeOnSelect || multiple); | ||||||||||||||||||||||||||
Comment on lines
+119
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议优化 isSelectable 函数的实现 当前实现逻辑正确,但可以更加简洁。建议合并条件判断,减少代码行数。 建议如下修改: const isSelectable = (option: DefaultOptionType) => {
- if (disabled) {
- return false;
- }
-
const { disabled: optionDisabled } = option;
const isMergedLeaf = isLeaf(option, fieldNames);
-
- return !optionDisabled && (isMergedLeaf || changeOnSelect || multiple);
+ return !disabled && !optionDisabled && (isMergedLeaf || changeOnSelect || multiple);
}; 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const onPathSelect = (valuePath: SingleValueType, leaf: boolean, fromKeyboard = false) => { | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
建议提取共同的 Panel 属性
多个
Cascader.Panel
组件都使用了相同的disabled
属性。建议将共同的属性提取为一个对象,以提高代码的可维护性和减少重复。Also applies to: 101-101, 104-104