Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
oa_process_monitor
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
oa_process_monitor
Commits
c2b5338a
Commit
c2b5338a
authored
Aug 27, 2026
by
Andy-bubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: stabilize multi-select autocomplete values
parent
bf90cc17
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
6 deletions
+91
-6
XinyuanAutocomplete.jsx
src/components/XinyuanAutocomplete.jsx
+91
-6
No files found.
src/components/XinyuanAutocomplete.jsx
View file @
c2b5338a
import
{
import
{
ChevronDown
,
ChevronDown
,
Check
,
Close
,
Close
,
FIELD_SUFFIX_ICON_STYLE
,
FIELD_SUFFIX_ICON_STYLE
,
Search
,
Search
,
...
@@ -17,6 +18,18 @@ function filterOption(textValue, inputValue) {
...
@@ -17,6 +18,18 @@ function filterOption(textValue, inputValue) {
return
!
query
||
String
(
textValue
||
''
).
toLocaleLowerCase
().
includes
(
query
);
return
!
query
||
String
(
textValue
||
''
).
toLocaleLowerCase
().
includes
(
query
);
}
}
function
getSelectedKeySet
(
selectionMode
,
selectedKey
,
selectedKeys
)
{
if
(
selectionMode
===
'multiple'
)
{
return
new
Set
(
selectedKeys
||
[]);
}
return
new
Set
(
selectedKey
===
null
||
selectedKey
===
undefined
?
[]
:
[
selectedKey
]);
}
function
toSelectionKey
(
value
)
{
return
String
(
value
??
''
);
}
export
default
function
XinyuanAutocomplete
({
export
default
function
XinyuanAutocomplete
({
'aria-label'
:
ariaLabel
,
'aria-label'
:
ariaLabel
,
className
,
className
,
...
@@ -28,24 +41,75 @@ export default function XinyuanAutocomplete({
...
@@ -28,24 +41,75 @@ export default function XinyuanAutocomplete({
placeholder
=
'请选择'
,
placeholder
=
'请选择'
,
searchPlaceholder
=
'输入关键词搜索'
,
searchPlaceholder
=
'输入关键词搜索'
,
selectedKey
,
selectedKey
,
selectedKeys
,
selectionMode
=
'single'
,
variant
=
'secondary'
,
variant
=
'secondary'
,
})
{
})
{
const
selectedOption
=
options
.
find
((
option
)
=>
option
.
id
===
selectedKey
);
const
selectedKeySet
=
getSelectedKeySet
(
selectionMode
,
selectedKey
,
selectedKeys
,
);
const
selectedKeyStringSet
=
new
Set
(
Array
.
from
(
selectedKeySet
).
map
(
toSelectionKey
),
);
const
selectedOptions
=
options
.
filter
((
option
)
=>
selectedKeyStringSet
.
has
(
toSelectionKey
(
option
.
id
)),
);
const
valueText
=
selectedOptions
.
length
?
selectedOptions
.
map
((
option
)
=>
option
.
label
).
join
(
'、'
)
:
placeholder
;
const
rootSelectionProps
=
selectionMode
===
'multiple'
?
{
selectedKeys
}
:
{
selectedKey
};
const
listBoxSelectionProps
=
selectionMode
===
'multiple'
?
{
selectionMode
,
selectedKeys
,
}
:
{};
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
);
};
return
(
return
(
<
Autocomplete
<
Autocomplete
{
...
rootSelectionProps
}
aria
-
label=
{
ariaLabel
||
placeholder
}
aria
-
label=
{
ariaLabel
||
placeholder
}
className=
{
className
}
className=
{
className
}
fullWidth=
{
fullWidth
}
fullWidth=
{
fullWidth
}
isDisabled=
{
isDisabled
}
isDisabled=
{
isDisabled
}
select
edKey=
{
selectedKey
}
select
ionMode=
{
selectionMode
}
variant=
{
variant
}
variant=
{
variant
}
onSelectionChange=
{
onSelectionChange
}
onSelectionChange=
{
onSelectionChange
}
>
>
<
Autocomplete
.
Trigger
>
<
Autocomplete
.
Trigger
>
<
Autocomplete
.
Value
>
<
Autocomplete
.
Value
>
<
span
className=
"block min-w-0 truncate"
>
<
span
className=
"block min-w-0 truncate"
>
{
selectedOption
?.
label
||
placeholder
}
{
valueText
}
</
span
>
</
span
>
</
Autocomplete
.
Value
>
</
Autocomplete
.
Value
>
<
Autocomplete
.
Indicator
>
<
Autocomplete
.
Indicator
>
...
@@ -71,18 +135,39 @@ export default function XinyuanAutocomplete({
...
@@ -71,18 +135,39 @@ export default function XinyuanAutocomplete({
<
ListBox
<
ListBox
aria
-
label=
{
ariaLabel
||
placeholder
}
aria
-
label=
{
ariaLabel
||
placeholder
}
items=
{
options
}
items=
{
options
}
{
...
listBoxSelectionProps
}
renderEmptyState=
{
()
=>
(
renderEmptyState=
{
()
=>
(
<
div
className=
"grid min-h-20 place-items-center px-3 py-4 text-sm text-muted"
>
<
div
className=
"grid min-h-20 place-items-center px-3 py-4 text-sm text-muted"
>
{
emptyText
}
{
emptyText
}
</
div
>
</
div
>
)
}
)
}
>
>
{
(
option
)
=>
(
{
(
option
)
=>
{
<
ListBox
.
Item
id=
{
option
.
id
}
textValue=
{
option
.
label
}
>
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) }
:
{}
)}
>
<
Label
className=
"truncate"
>
{
option
.
label
}
</
Label
>
<
Label
className=
"truncate"
>
{
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
.
ItemIndicator
/>
</
ListBox
.
Item
>
)
}
)
}
</
ListBox
.
Item
>
);
}
}
</
ListBox
>
</
ListBox
>
</
Autocomplete
.
Filter
>
</
Autocomplete
.
Filter
>
</
Autocomplete
.
Popover
>
</
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