-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Options null value warning (#303)
* chore: add latest prettier to devDependencies * feat: add null is a value warning * test: add null is a value warning test cases
- Loading branch information
1 parent
d7fac6a
commit 5cb966c
Showing
5 changed files
with
128 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import warning from 'rc-util/lib/warning'; | ||
import type { DefaultOptionType, FieldNames, InternalCascaderProps } from '../Cascader'; | ||
|
||
function warningProps(props: InternalCascaderProps) { | ||
const { onPopupVisibleChange, popupVisible, popupClassName, popupPlacement } = props; | ||
|
||
warning( | ||
!onPopupVisibleChange, | ||
'`onPopupVisibleChange` is deprecated. Please use `onDropdownVisibleChange` instead.', | ||
); | ||
warning(popupVisible === undefined, '`popupVisible` is deprecated. Please use `open` instead.'); | ||
warning( | ||
popupClassName === undefined, | ||
'`popupClassName` is deprecated. Please use `dropdownClassName` instead.', | ||
); | ||
warning( | ||
popupPlacement === undefined, | ||
'`popupPlacement` is deprecated. Please use `placement` instead.', | ||
); | ||
} | ||
|
||
// value in Cascader options should not be null | ||
export function warningNullOptions(options: DefaultOptionType[], fieldNames: FieldNames) { | ||
if (options) { | ||
const recursiveOptions = (optionsList: DefaultOptionType[]) => { | ||
for (let i = 0; i < optionsList.length; i++) { | ||
const option = optionsList[i]; | ||
|
||
if (option[fieldNames?.value] === null) { | ||
warning(false, '`value` in Cascader options should not be `null`.'); | ||
return true; | ||
} | ||
|
||
if ( | ||
Array.isArray(option[fieldNames?.children]) && | ||
recursiveOptions(option[fieldNames?.children]) | ||
) { | ||
return true; | ||
} | ||
} | ||
}; | ||
|
||
recursiveOptions(options); | ||
} | ||
} | ||
|
||
export default warningProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5cb966c
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.
Successfully deployed to the following URLs:
cascader – ./
cascader-git-master-react-component.vercel.app
cascader-react-component.vercel.app