Skip to content

Commit 4751c58

Browse files
authored
fix: UTC-545: fix: UTC-544: Improvement: Checkboxes are not selected on UI when 'Select All' is selected (#9360)
Co-authored-by: nass600 <nass600@users.noreply.github.com>
1 parent ebdce23 commit 4751c58

File tree

3 files changed

+50
-56
lines changed

3 files changed

+50
-56
lines changed

web/libs/ui/src/lib/select/select.module.scss

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -137,34 +137,3 @@
137137
border-top: 1px solid var(--color-neutral-border-subtler);
138138
}
139139

140-
.selectedItem {
141-
display: flex;
142-
align-items: center;
143-
gap: var(--spacing-tight);
144-
padding: var(--spacing-tight);
145-
padding-left: var(--spacing-widest);
146-
cursor: pointer;
147-
transition: background 150ms ease-out;
148-
149-
// Button reset styles
150-
width: 100%;
151-
border: none;
152-
background: transparent;
153-
text-align: left;
154-
font: inherit;
155-
color: inherit;
156-
157-
&:hover:not(:disabled) {
158-
background: var(--color-primary-background-hover);
159-
}
160-
161-
&:focus {
162-
outline: 2px solid var(--color-primary-border);
163-
outline-offset: -2px;
164-
}
165-
166-
&:disabled {
167-
cursor: not-allowed;
168-
opacity: 0.5;
169-
}
170-
}

web/libs/ui/src/lib/select/select.tsx

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,48 @@ const SelectedItemsGroup = ({
6666
[onDeselectAll, disabled],
6767
);
6868

69+
const hasNoItems = selectedOptions.length === 0;
70+
71+
// Collapse the group when no items are selected
72+
useEffect(() => {
73+
if (hasNoItems && expanded) {
74+
onToggleExpand();
75+
}
76+
}, [hasNoItems, expanded, onToggleExpand]);
77+
6978
return (
7079
<div className={styles.selectedItemsGroup}>
7180
{/* Header - Always visible */}
7281
<button
7382
type="button"
7483
className={styles.selectedItemsHeader}
75-
onClick={onToggleExpand}
84+
onClick={hasNoItems ? undefined : onToggleExpand}
7685
aria-expanded={expanded}
7786
aria-label={`Selected items group, ${selectedOptions.length} items selected`}
87+
disabled={hasNoItems}
88+
style={{ cursor: hasNoItems ? "default" : "pointer" }}
7889
>
7990
{/* Caret icon */}
8091
{expanded ? (
81-
<IconChevron className={styles.selectedItemsCaret} aria-hidden="true" />
92+
<IconChevron
93+
className={styles.selectedItemsCaret}
94+
aria-hidden="true"
95+
style={{ opacity: hasNoItems ? 0.3 : 1 }}
96+
/>
8297
) : (
83-
<IconChevronDown className={styles.selectedItemsCaret} aria-hidden="true" />
98+
<IconChevronDown
99+
className={styles.selectedItemsCaret}
100+
aria-hidden="true"
101+
style={{ opacity: hasNoItems ? 0.3 : 1 }}
102+
/>
84103
)}
85104

86105
{/* Deselect all checkbox */}
87106
<Checkbox
88107
tabIndex={-1}
89-
checked={true}
108+
checked={selectedOptions.length > 0}
90109
readOnly
91-
disabled={disabled}
110+
disabled={disabled || selectedOptions.length === 0}
92111
onClick={handleDeselectAllClick}
93112
aria-label="Deselect all items"
94113
/>
@@ -105,25 +124,29 @@ const SelectedItemsGroup = ({
105124
{/* Content - Conditionally rendered when expanded */}
106125
{expanded && (
107126
<div className={styles.selectedItemsContent}>
108-
{selectedOptions.map((option, index) => {
109-
const optionValue = option?.value ?? option;
110-
const label = option?.label ?? optionValue;
111-
112-
return (
113-
<button
114-
key={`selected-${optionValue}-${index}`}
115-
type="button"
116-
className={styles.selectedItem}
117-
onClick={() => handleItemClick(option)}
118-
tabIndex={disabled ? -1 : 0}
119-
aria-label={`Deselect ${label}`}
120-
disabled={disabled}
121-
>
122-
<Checkbox tabIndex={-1} checked={true} readOnly disabled={disabled} />
123-
<div className="w-full min-w-0 truncate">{label}</div>
124-
</button>
125-
);
126-
})}
127+
{selectedOptions.length > 0 ? (
128+
<CommandGroup>
129+
{selectedOptions.map((option, index) => {
130+
const optionValue = option?.value ?? option;
131+
const label = option?.label ?? optionValue;
132+
133+
return (
134+
<Option
135+
key={`selected-${optionValue}-${index}`}
136+
value={optionValue}
137+
label={label}
138+
isOptionSelected={true}
139+
disabled={disabled}
140+
multiple={true}
141+
onSelect={() => handleItemClick(option)}
142+
style={{ paddingLeft: "var(--spacing-wider)" }}
143+
/>
144+
);
145+
})}
146+
</CommandGroup>
147+
) : (
148+
<div className="px-base py-tight text-neutral-content-subtler text-center">No items selected</div>
149+
)}
127150
</div>
128151
)}
129152
</div>
@@ -199,6 +222,7 @@ export const Select = forwardRef(
199222
onClose,
200223
onOpen,
201224
footer,
225+
alwaysShowSelectedGroup = false,
202226
...props
203227
}: SelectProps<T, A>,
204228
_ref: ForwardedRef<HTMLSelectElement>,
@@ -512,7 +536,7 @@ export const Select = forwardRef(
512536
})}
513537
>
514538
{/* Selected Items Group - Only for multiple + searchable + virtual lists */}
515-
{multiple && searchable && isVirtualList && selectedOptions.length > 0 && (
539+
{multiple && searchable && isVirtualList && (selectedOptions.length > 0 || alwaysShowSelectedGroup) && (
516540
<SelectedItemsGroup
517541
expanded={selectedGroupExpanded}
518542
onToggleExpand={() => setSelectedGroupExpanded(!selectedGroupExpanded)}

web/libs/ui/src/lib/select/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export type SelectProps<T, A extends SelectOption<T>[]> = {
8888
itemCount?: number;
8989
onClose?: () => void;
9090
onOpen?: () => void;
91+
alwaysShowSelectedGroup?: boolean;
9192
} & SelectVirtualizedProps &
9293
Omit<React.SelectHTMLAttributes<HTMLSelectElement>, "value" | "placeholder">;
9394

0 commit comments

Comments
 (0)