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): fix valueDisplay onClose callback #3154

Merged
merged 2 commits into from
Oct 22, 2024
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
15 changes: 13 additions & 2 deletions src/select/_example/custom-selected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,19 @@ const CustomSelected = () => {
{ label: '选项八', value: '8' },
{ label: '选项九', value: '9' },
]}
valueDisplay={({ value }) =>
Array.isArray(value) && value.length > 0 ? value.map((v, idx) => <Tag key={idx}>{`${v}选项`}</Tag>) : null
valueDisplay={({ value, onClose }) =>
Array.isArray(value) && value.length > 0
? value.map((v: string, idx: number) => (
<Tag
key={idx}
onClose={(context) => {
context.e && context.e.stopPropagation();
onClose(idx);
}}
closable
>{`${v}选项`}</Tag>
))
: null
}
/>
</Space>
Expand Down
2 changes: 1 addition & 1 deletion src/select/base/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const Select = forwardRefWithStatics(
}

if (trigger === 'tag-remove') {
e.stopPropagation();
e?.stopPropagation?.();
const values = getSelectValueArr(value, value[index], true, valueType, keys);
// 处理onChange回调中的selectedOptions参数
const currentSelectedOptions = getSelectedOptions(values, multiple, valueType, keys, tmpPropOptions);
Expand Down
36 changes: 36 additions & 0 deletions test/snap/__snapshots__/csr.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -74469,6 +74469,18 @@ exports[`csr snapshot test > csr test src/select/_example/custom-selected.tsx 1`
>
选项一选项
</span>
<svg
class="t-icon t-icon-close t-tag__icon-close"
fill="none"
height="1em"
viewBox="0 0 24 24"
width="1em"
>
<path
d="M7.05 5.64L12 10.59l4.95-4.95 1.41 1.41L13.41 12l4.95 4.95-1.41 1.41L12 13.41l-4.95 4.95-1.41-1.41L10.59 12 5.64 7.05l1.41-1.41z"
fill="currentColor"
/>
</svg>
</div>
<div
class="t-tag t-tag--default t-tag--dark"
Expand All @@ -74478,6 +74490,18 @@ exports[`csr snapshot test > csr test src/select/_example/custom-selected.tsx 1`
>
选项二选项
</span>
<svg
class="t-icon t-icon-close t-tag__icon-close"
fill="none"
height="1em"
viewBox="0 0 24 24"
width="1em"
>
<path
d="M7.05 5.64L12 10.59l4.95-4.95 1.41 1.41L13.41 12l4.95 4.95-1.41 1.41L12 13.41l-4.95 4.95-1.41-1.41L10.59 12 5.64 7.05l1.41-1.41z"
fill="currentColor"
/>
</svg>
</div>
<div
class="t-tag t-tag--default t-tag--dark"
Expand All @@ -74487,6 +74511,18 @@ exports[`csr snapshot test > csr test src/select/_example/custom-selected.tsx 1`
>
选项三选项
</span>
<svg
class="t-icon t-icon-close t-tag__icon-close"
fill="none"
height="1em"
viewBox="0 0 24 24"
width="1em"
>
<path
d="M7.05 5.64L12 10.59l4.95-4.95 1.41 1.41L13.41 12l4.95 4.95-1.41 1.41L12 13.41l-4.95 4.95-1.41-1.41L10.59 12 5.64 7.05l1.41-1.41z"
fill="currentColor"
/>
</svg>
</div>
</div>
<span
Expand Down
Loading