Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
I
integrity_practice_management_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
integrity_practice_management_new
Commits
da2b0019
Commit
da2b0019
authored
Aug 27, 2026
by
Andy-bubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: stabilize multi-select autocomplete values
parent
84dfb853
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
9 deletions
+74
-9
XinyuanAutocomplete.jsx
src/components/XinyuanAutocomplete.jsx
+64
-4
TailwindEditableField.jsx
...s/RecordDetailDrawer/components/TailwindEditableField.jsx
+10
-5
No files found.
src/components/XinyuanAutocomplete.jsx
View file @
da2b0019
import
{
import
{
ChevronDown
,
ChevronDown
,
Check
,
Close
,
Close
,
FIELD_SUFFIX_ICON_STYLE
,
FIELD_SUFFIX_ICON_STYLE
,
Search
,
Search
,
...
@@ -25,6 +26,10 @@ function getSelectedKeySet(selectionMode, selectedKey, selectedKeys) {
...
@@ -25,6 +26,10 @@ function getSelectedKeySet(selectionMode, selectedKey, selectedKeys) {
return
new
Set
(
selectedKey
===
null
||
selectedKey
===
undefined
?
[]
:
[
selectedKey
]);
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
,
...
@@ -59,8 +64,12 @@ export default function XinyuanAutocomplete({
...
@@ -59,8 +64,12 @@ export default function XinyuanAutocomplete({
selectedKey
,
selectedKey
,
selectedKeys
,
selectedKeys
,
);
);
const
selectedKeyStringSet
=
new
Set
(
Array
.
from
(
selectedKeySet
).
map
(
toSelectionKey
),
);
const
selectedOptions
=
options
.
filter
((
option
)
=>
const
selectedOptions
=
options
.
filter
((
option
)
=>
selectedKeySet
.
has
(
option
.
id
),
selectedKeySet
.
has
(
option
.
id
)
||
selectedKeyStringSet
.
has
(
toSelectionKey
(
option
.
id
)),
);
);
const
resolvedValueText
=
const
resolvedValueText
=
valueText
??
valueText
??
...
@@ -69,9 +78,40 @@ export default function XinyuanAutocomplete({
...
@@ -69,9 +78,40 @@ export default function XinyuanAutocomplete({
:
placeholder
);
:
placeholder
);
const
rootSelectionProps
=
const
rootSelectionProps
=
selectionMode
===
'multiple'
selectionMode
===
'multiple'
?
{
selectedKeys
}
?
{
selectedKeys
:
selectedKeyStringSet
}
:
{
selectedKey
};
:
{
selectedKey
};
const
listBoxSelectionProps
=
selectionMode
===
'multiple'
?
{
selectionMode
,
selectedKeys
:
selectedKeyStringSet
,
}
:
{};
const
visibleOptions
=
isLoading
||
errorText
?
[]
:
options
;
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
);
};
return
(
return
(
<
Autocomplete
<
Autocomplete
...
@@ -125,7 +165,11 @@ export default function XinyuanAutocomplete({
...
@@ -125,7 +165,11 @@ export default function XinyuanAutocomplete({
</
SearchField
>
</
SearchField
>
<
ListBox
<
ListBox
aria
-
label=
{
ariaLabel
||
placeholder
}
aria
-
label=
{
ariaLabel
||
placeholder
}
dependencies=
{
[
Array
.
from
(
selectedKeyStringSet
).
sort
().
join
(
'
\
u0000'
),
]
}
items=
{
visibleOptions
}
items=
{
visibleOptions
}
{
...
listBoxSelectionProps
}
renderEmptyState=
{
()
=>
(
renderEmptyState=
{
()
=>
(
<
div
<
div
className=
"grid min-h-20 place-items-center px-3 py-4"
className=
"grid min-h-20 place-items-center px-3 py-4"
...
@@ -135,11 +179,17 @@ export default function XinyuanAutocomplete({
...
@@ -135,11 +179,17 @@ export default function XinyuanAutocomplete({
</
div
>
</
div
>
)
}
)
}
>
>
{
(
option
)
=>
(
{
(
option
)
=>
{
const
isSelected
=
selectedKeyStringSet
.
has
(
toSelectionKey
(
option
.
id
));
return
(
<
ListBox
.
Item
<
ListBox
.
Item
id=
{
option
.
id
}
id=
{
option
.
id
}
isDisabled=
{
option
.
isDisabled
}
isDisabled=
{
option
.
isDisabled
}
textValue=
{
option
.
textValue
||
option
.
label
}
textValue=
{
option
.
textValue
||
option
.
label
}
{
...
(
selectionMode
===
'
multiple
'
?
{
onPress
:
()
=
>
handleMultipleOptionPress(option) }
:
{}
)}
>
>
{
renderOption
?
(
{
renderOption
?
(
renderOption
(
option
)
renderOption
(
option
)
...
@@ -148,9 +198,19 @@ export default function XinyuanAutocomplete({
...
@@ -148,9 +198,19 @@ export default function XinyuanAutocomplete({
{
option
.
label
}
{
option
.
label
}
</
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
>
...
...
src/pages/RecordDetailDrawer/components/TailwindEditableField.jsx
View file @
da2b0019
...
@@ -258,6 +258,10 @@ function UserSelector({ value, onChange, multiple, variant }) {
...
@@ -258,6 +258,10 @@ function UserSelector({ value, onChange, multiple, variant }) {
function
FieldOptionSelect
({
multiple
,
onChange
,
options
,
value
,
variant
})
{
function
FieldOptionSelect
({
multiple
,
onChange
,
options
,
value
,
variant
})
{
const
values
=
multiple
?
toArray
(
value
).
map
(
String
)
:
[
String
(
value
||
''
)];
const
values
=
multiple
?
toArray
(
value
).
map
(
String
)
:
[
String
(
value
||
''
)];
const
selectedOptions
=
options
.
filter
((
option
)
=>
values
.
includes
(
String
(
option
.
value
)));
const
selectedOptions
=
options
.
filter
((
option
)
=>
values
.
includes
(
String
(
option
.
value
)));
const
autocompleteOptions
=
options
.
map
((
option
)
=>
({
id
:
String
(
option
.
value
),
label
:
option
.
label
,
}));
const
displayValue
=
selectedOptions
.
length
const
displayValue
=
selectedOptions
.
length
?
selectedOptions
.
map
((
option
)
=>
option
.
label
).
join
(
'、'
)
?
selectedOptions
.
map
((
option
)
=>
option
.
label
).
join
(
'、'
)
:
'请选择'
;
:
'请选择'
;
...
@@ -265,7 +269,11 @@ function FieldOptionSelect({ multiple, onChange, options, value, variant }) {
...
@@ -265,7 +269,11 @@ function FieldOptionSelect({ multiple, onChange, options, value, variant }) {
?
{
?
{
selectedKeys
:
new
Set
(
values
),
selectedKeys
:
new
Set
(
values
),
onSelectionChange
:
(
keys
)
=>
onSelectionChange
:
(
keys
)
=>
onChange
(
keys
===
'all'
?
options
.
map
((
option
)
=>
option
.
value
)
:
[...
keys
]),
onChange
(
keys
===
'all'
?
autocompleteOptions
.
map
((
option
)
=>
option
.
id
)
:
[...
keys
],
),
}
}
:
{
:
{
selectedKey
:
values
[
0
]
||
null
,
selectedKey
:
values
[
0
]
||
null
,
...
@@ -276,10 +284,7 @@ function FieldOptionSelect({ multiple, onChange, options, value, variant }) {
...
@@ -276,10 +284,7 @@ function FieldOptionSelect({ multiple, onChange, options, value, variant }) {
<
XinyuanAutocomplete
<
XinyuanAutocomplete
{
...
selectProps
}
{
...
selectProps
}
aria
-
label=
"选择字段值"
aria
-
label=
"选择字段值"
options=
{
options
.
map
((
option
)
=>
({
options=
{
autocompleteOptions
}
id
:
String
(
option
.
value
),
label
:
option
.
label
,
}))
}
placeholder=
"请选择"
placeholder=
"请选择"
selectionMode=
{
multiple
?
'multiple'
:
'single'
}
selectionMode=
{
multiple
?
'multiple'
:
'single'
}
valueText=
{
displayValue
}
valueText=
{
displayValue
}
...
...
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