Skip to content

Commit 9f3c6a9

Browse files
authored
fix: normal list mode cannot be selected (#67)
1 parent 481b687 commit 9f3c6a9

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

.changes/fix-list-selection.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@matechat/react": patch:fix
3+
---
4+
5+
Fixed the issue that normal list mode cannot be selected.
6+
7+
Other optimizations:
8+
- Remove the `className` attribute from the `list`.
9+
- Add an id attribute to the li option of the list component.

src/list.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ interface OptionGroupItem {
5757
export type MixedOptionArray = Array<OptionGroupItem | OptionData>;
5858

5959
export const List = ({
60-
className,
6160
listBoxStyle,
6261
listGroupStyle,
6362
listItemStyle,
@@ -74,15 +73,16 @@ export const List = ({
7473
event: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,
7574
option: UnknownRecord,
7675
) => {
76+
const optionValue = option[optionLabel];
7777
const changeEvent: ListChangeEvent = {
7878
originalEvent: event,
79-
value: option[optionLabel],
79+
value: optionValue,
8080
stopPropagation: () => event.stopPropagation(),
8181
preventDefault: () => event.preventDefault(),
8282
target: {
8383
name: option.label?.toString() || "",
84-
id: option.value?.toString() || "",
85-
value: option[optionLabel],
84+
id: "list",
85+
value: optionValue,
8686
},
8787
};
8888
onChange?.(changeEvent);
@@ -139,12 +139,11 @@ export const List = ({
139139
const optionData = option as OptionData;
140140
const optionKey = optionData[optionLabel as keyof OptionData];
141141
const key = `option_${index}_${String(optionKey)}`;
142-
143142
const handleClick = (e: React.MouseEvent<HTMLElement>) => {
144143
handleSelect(e, optionData);
145144
};
146145

147-
const optionValue = optionData.value;
146+
const optionValue = optionData[optionLabel];
148147
const isSelected = String(optionValue) === String(value);
149148

150149
return (
@@ -156,6 +155,7 @@ export const List = ({
156155
"bg-blue-500 text-white hover:bg-blue-600": isSelected,
157156
}),
158157
)}
158+
id={`lo_id_${index}`}
159159
style={listItemStyle}
160160
onClick={handleClick}
161161
onKeyDown={(e) => {

0 commit comments

Comments
 (0)