Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
A
audit_manager_new
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
David Yang
audit_manager_new
Commits
2a30208c
Commit
2a30208c
authored
Aug 27, 2026
by
Andy-bubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: stabilize multi-select autocomplete values
parent
e5b0ea0c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
3 deletions
+60
-3
XinyuanAutocomplete.jsx
src/components/XinyuanAutocomplete.jsx
+60
-3
No files found.
src/components/XinyuanAutocomplete.jsx
View file @
2a30208c
import
{
ChevronDown
,
Check
,
Close
,
FIELD_SUFFIX_ICON_STYLE
,
Search
,
...
...
@@ -27,6 +28,10 @@ function getSelectedKeySet(selectionMode, selectedKey, selectedKeys) {
return
new
Set
(
selectedKey
===
null
||
selectedKey
===
undefined
?
[]
:
[
selectedKey
]);
}
function
toSelectionKey
(
value
)
{
return
String
(
value
??
''
);
}
export
default
function
XinyuanAutocomplete
({
'aria-label'
:
ariaLabel
,
className
,
...
...
@@ -62,8 +67,12 @@ export default function XinyuanAutocomplete({
selectedKey
,
selectedKeys
,
);
const
selectedKeyStringSet
=
new
Set
(
Array
.
from
(
selectedKeySet
).
map
(
toSelectionKey
),
);
const
selectedOptions
=
options
.
filter
((
option
)
=>
selectedKeySet
.
has
(
option
.
id
),
selectedKeySet
.
has
(
option
.
id
)
||
selectedKeyStringSet
.
has
(
toSelectionKey
(
option
.
id
)),
);
const
resolvedValueText
=
valueText
??
...
...
@@ -74,7 +83,38 @@ export default function XinyuanAutocomplete({
selectionMode
===
'multiple'
?
{
selectedKeys
}
:
{
selectedKey
};
const
listBoxSelectionProps
=
selectionMode
===
'multiple'
?
{
selectionMode
,
selectedKeys
,
}
:
{};
const
visibleOptions
=
isLoading
||
errorText
?
[]
:
options
;
const
handleMultipleOptionPress
=
(
option
)
=>
{
if
(
selectionMode
!==
'multiple'
||
!
onSelectionChange
||
option
?.
isDisabled
)
{
return
;
}
const
optionKey
=
toSelectionKey
(
option
.
id
);
if
(
!
optionKey
)
{
return
;
}
const
nextKeys
=
new
Set
(
Array
.
from
(
selectedKeyStringSet
).
filter
(
Boolean
),
);
if
(
nextKeys
.
has
(
optionKey
))
{
nextKeys
.
delete
(
optionKey
);
}
else
{
nextKeys
.
add
(
optionKey
);
}
onSelectionChange
(
nextKeys
);
};
const
defaultValue
=
selectionMode
===
'multiple'
&&
selectedOptions
.
length
>
0
?
(
<
TagGroup
aria
-
label=
"已选择项"
...
...
@@ -161,6 +201,7 @@ export default function XinyuanAutocomplete({
<
ListBox
aria
-
label=
{
ariaLabel
||
placeholder
}
items=
{
visibleOptions
}
{
...
listBoxSelectionProps
}
renderEmptyState=
{
()
=>
(
<
div
className=
"grid min-h-20 place-items-center px-3 py-4"
...
...
@@ -170,11 +211,17 @@ export default function XinyuanAutocomplete({
</
div
>
)
}
>
{
(
option
)
=>
(
{
(
option
)
=>
{
const
isSelected
=
selectedKeyStringSet
.
has
(
toSelectionKey
(
option
.
id
));
return
(
<
ListBox
.
Item
id=
{
option
.
id
}
isDisabled=
{
option
.
isDisabled
}
textValue=
{
option
.
textValue
||
option
.
label
}
{
...
(
selectionMode
===
'
multiple
'
?
{
onPress
:
()
=
>
handleMultipleOptionPress(option) }
:
{}
)}
>
{
renderOption
?
(
renderOption
(
option
)
...
...
@@ -183,9 +230,19 @@ export default function XinyuanAutocomplete({
{
option
.
label
}
</
Label
>
)
}
{
selectionMode
===
'multiple'
?
(
<
span
aria
-
hidden=
"true"
className=
"ml-auto inline-flex w-5 justify-center text-foreground"
>
{
isSelected
?
<
Check
size=
{
14
}
/>
:
null
}
</
span
>
)
:
(
<
ListBox
.
ItemIndicator
/>
</
ListBox
.
Item
>
)
}
</
ListBox
.
Item
>
);
}
}
</
ListBox
>
</
Autocomplete
.
Filter
>
</
Autocomplete
.
Popover
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment