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: cascader value check #1170

Merged
merged 4 commits into from
Jul 26, 2022
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
29 changes: 0 additions & 29 deletions src/calendar/__tests__/__snapshots__/calendar.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ exports[`base.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -93,7 +92,6 @@ exports[`base.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down Expand Up @@ -682,7 +680,6 @@ exports[`card.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -738,7 +735,6 @@ exports[`card.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down Expand Up @@ -1211,7 +1207,6 @@ exports[`cell.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -1267,7 +1262,6 @@ exports[`cell.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down Expand Up @@ -1932,7 +1926,6 @@ exports[`cell-append.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -1988,7 +1981,6 @@ exports[`cell-append.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down Expand Up @@ -2843,7 +2835,6 @@ exports[`controller-config.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -2899,7 +2890,6 @@ exports[`controller-config.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down Expand Up @@ -3416,7 +3406,6 @@ exports[`event-props-api.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -3472,7 +3461,6 @@ exports[`event-props-api.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down Expand Up @@ -4005,7 +3993,6 @@ exports[`events.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -4061,7 +4048,6 @@ exports[`events.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down Expand Up @@ -4576,7 +4562,6 @@ exports[`filter.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -4632,7 +4617,6 @@ exports[`filter.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down Expand Up @@ -5182,7 +5166,6 @@ exports[`first-day-of-week.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -5238,7 +5221,6 @@ exports[`first-day-of-week.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down Expand Up @@ -5780,7 +5762,6 @@ exports[`head.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -5836,7 +5817,6 @@ exports[`head.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down Expand Up @@ -6385,7 +6365,6 @@ exports[`mode.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -6659,7 +6638,6 @@ exports[`range.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -6715,7 +6693,6 @@ exports[`range.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down Expand Up @@ -7213,7 +7190,6 @@ exports[`slot-props-api.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -7269,7 +7245,6 @@ exports[`slot-props-api.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down Expand Up @@ -7934,7 +7909,6 @@ exports[`value.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="1998 年"
/>
Expand Down Expand Up @@ -7990,7 +7964,6 @@ exports[`value.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="11 月"
/>
Expand Down Expand Up @@ -8484,7 +8457,6 @@ exports[`week.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="2021 年"
/>
Expand Down Expand Up @@ -8540,7 +8512,6 @@ exports[`week.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value="8 月"
/>
Expand Down
7 changes: 0 additions & 7 deletions src/cascader/__tests__/__snapshots__/cascader.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ exports[`filterable.jsx 1`] = `
<input
class="t-input__inner"
placeholder=""
style="width: 0px;"
type="text"
value=""
/>
Expand Down Expand Up @@ -632,7 +631,6 @@ exports[`keys.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value=""
/>
Expand Down Expand Up @@ -740,7 +738,6 @@ exports[`max.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value=""
/>
Expand Down Expand Up @@ -1058,7 +1055,6 @@ exports[`show-all-levels.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value=""
/>
Expand Down Expand Up @@ -1346,7 +1342,6 @@ exports[`value-mode.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value=""
/>
Expand Down Expand Up @@ -1394,7 +1389,6 @@ exports[`value-mode.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value=""
/>
Expand Down Expand Up @@ -1442,7 +1436,6 @@ exports[`value-mode.jsx 1`] = `
class="t-input__inner"
placeholder="请选择"
readonly=""
style="width: 0px;"
type="text"
value=""
/>
Expand Down
9 changes: 3 additions & 6 deletions src/cascader/core/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ import {
* @param cascaderContext
* @returns
*/
export function getSingleContent(cascaderContext: CascaderContextType) {
const { value, multiple, treeStore, showAllLevels, setValue } = cascaderContext;
export function getSingleContent(cascaderContext: CascaderContextType): string {
const { value, multiple, treeStore, showAllLevels } = cascaderContext;
if (multiple || !value) return '';

if (Array.isArray(value)) return '';
const node = treeStore && treeStore.getNodes(value as TreeNodeValue | TreeNode);
if (!(node && node.length)) {
if (value) {
setValue(multiple ? [] : '', 'invalid-value');
}
return '';
return value as string;
}
const path = node && node[0].getPath();
if (path && path.length) {
Expand Down
Loading