Skip to content

Commit

Permalink
fix(Select): fix valueDisplay onClose callback (#3154)
Browse files Browse the repository at this point in the history
* fix(Select): fix valueDisplay onclose callback

* chore: update snapshot

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
uyarn and github-actions[bot] authored Oct 22, 2024
1 parent 4c70727 commit e4e6681
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
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

0 comments on commit e4e6681

Please sign in to comment.