Skip to content

Commit 93c946f

Browse files
committed
change the architecture of the enhance choice component, from heavily reliability with react-aria to less reliability
1 parent 9d9e751 commit 93c946f

14 files changed

Lines changed: 1576 additions & 543 deletions

File tree

assets/build/beaver-builder/index.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/build/default/index.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/build/elementor/index.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/build/example.min.js

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/build/index.min.js

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/build/wp/index.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/src/components/field/enhanced-choice/EnhancedListBox.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import { useListBox } from "react-aria"; // FIX — useListBox was used but never imported
1+
import { useListBox } from "react-aria";
22
import EnhancedOption from "./EnhancedOption";
33

4-
const EnhancedListBox = ({ listBoxRef, state, name, pendingKey, ...props }) => {
4+
const EnhancedListBox = ({ listBoxRef, state, name, pendingKey, pendingKeys, onSelectionChange, ...props }) => {
55

66
const { listBoxProps } = useListBox(props, state, listBoxRef);
77

8+
const isPendingKey = (key) =>
9+
pendingKeys ? pendingKeys.includes(key) : pendingKey === key;
10+
811
return (
912
<ul
1013
{...listBoxProps}
@@ -22,7 +25,8 @@ const EnhancedListBox = ({ listBoxRef, state, name, pendingKey, ...props }) => {
2225
item={child}
2326
state={state}
2427
name={name}
25-
isPending={pendingKey === child.key}
28+
isPending={isPendingKey(child.key)}
29+
onSelectionChange={onSelectionChange}
2630
isVisibilityEnabled={props.isVisibilityEnabled}
2731
onToggleVisibility={props.onToggleVisibility}
2832
visibility={props.visibility}
@@ -37,7 +41,8 @@ const EnhancedListBox = ({ listBoxRef, state, name, pendingKey, ...props }) => {
3741
state={state}
3842
name={name}
3943
visibility={props.visibility}
40-
isPending={pendingKey === item.key}
44+
isPending={isPendingKey(item.key)}
45+
onSelectionChange={onSelectionChange}
4146
isVisibilityEnabled={props.isVisibilityEnabled}
4247
onToggleVisibility={props.onToggleVisibility}
4348
/>

assets/src/components/field/enhanced-choice/EnhancedOption.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ import { useRef } from 'react';
22
import { useOption, mergeProps, useFocusRing } from 'react-aria';
33
import Checkbox from '../checkbox/Checkbox';
44

5-
const EnhancedOption = ({ item, state, isVisibilityEnabled, name, visibility = {}, onToggleVisibility, isPending }) => {
5+
const EnhancedOption = ({
6+
item,
7+
state,
8+
isVisibilityEnabled,
9+
name,
10+
visibility = {},
11+
onToggleVisibility,
12+
isPending,
13+
onSelectionChange,
14+
}) => {
615
const ref = useRef(null);
716

817
const {
@@ -18,7 +27,6 @@ const EnhancedOption = ({ item, state, isVisibilityEnabled, name, visibility = {
1827
const isSingle = state.selectionManager.selectionMode === 'single';
1928

2029
const handleEyeClick = (e) => {
21-
e.stopPropagation();
2230
e.preventDefault();
2331
onToggleVisibility?.(item.key);
2432
};
@@ -27,17 +35,28 @@ const EnhancedOption = ({ item, state, isVisibilityEnabled, name, visibility = {
2735
e.stopPropagation();
2836
};
2937

30-
const isMarked = isSelected || isPending;
31-
38+
const isMarked = isSingle ? (isSelected || isPending) : isPending;
39+
3240
let classes = 'tf-enhanced-choice-option';
3341
if (isMarked) classes += ' is-selected';
3442
if (isFocused) classes += ' is-focused';
3543
if (isDisabled) classes += ' is-disabled';
36-
if (isPending && !isSelected) classes += ' is-pending';
44+
45+
const handleMultipleClick = (e) => {
46+
e.preventDefault();
47+
if (!isDisabled) onSelectionChange?.(item.key);
48+
};
49+
50+
const liProps = isSingle
51+
? mergeProps(optionProps, focusProps)
52+
: mergeProps(optionProps, focusProps, {
53+
onClick: handleMultipleClick,
54+
onMouseDown: (e) => e.preventDefault(),
55+
});
3756

3857
return (
3958
<li
40-
{...mergeProps(optionProps, focusProps)}
59+
{...liProps}
4160
ref={ref}
4261
className={classes}
4362
data-focus-visible={isFocusVisible}
@@ -54,7 +73,7 @@ const EnhancedOption = ({ item, state, isVisibilityEnabled, name, visibility = {
5473
/>
5574
) : (
5675
<Checkbox
57-
isSelected={isSelected}
76+
isSelected={isMarked}
5877
isDisabled={isDisabled}
5978
/>
6079
)}

0 commit comments

Comments
 (0)