Skip to content

Commit 9c1ee2d

Browse files
fix: Card select issue in selectable card (#564)
Co-authored-by: tumms2021389 <97188066+tumms2021389@users.noreply.github.com>
1 parent 72701b9 commit 9c1ee2d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

packages/react-sdk-components/src/components/field/SelectableCard/SelectableCard.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ export default function SelectableCard(props) {
3333
const cardDataSource = readOnly || displayMode === 'DISPLAY_ONLY' ? readOnlyList || [] : dataSource?.source;
3434
const imageDescriptionKey = showImageDescription ? imageDescription : undefined;
3535

36+
const handleCardClick = event => {
37+
if (disabled || readOnly) return;
38+
// If the click landed on or inside a label/input, native behavior already handles it.
39+
if (event.target.closest?.('label, input')) return;
40+
// Find the radio/checkbox input inside this card and click it programmatically.
41+
const input = event.currentTarget.querySelector('input[type="radio"], input[type="checkbox"]');
42+
if (input) input.click();
43+
};
44+
3645
let radioItemSelected = false;
3746

3847
return (
@@ -75,7 +84,12 @@ export default function SelectableCard(props) {
7584

7685
const component = (
7786
<div key={item[recordKey]} style={{ paddingTop: '15px' }}>
78-
<Card className={className} style={{ display: 'flex', flexDirection: 'column', height: '100%' }} data-testid={testId}>
87+
<Card
88+
className={className}
89+
style={{ display: 'flex', flexDirection: 'column', height: '100%', cursor: disabled || readOnly ? 'default' : 'pointer' }}
90+
data-testid={testId}
91+
onClick={handleCardClick}
92+
>
7993
<CardContent
8094
style={{
8195
...((imagePosition === 'inline-start' || imagePosition === 'inline-end') && { display: 'flex', height: '100%' }),
@@ -118,7 +132,7 @@ export default function SelectableCard(props) {
118132
onBlur={onBlur}
119133
onClick={onClick}
120134
onKeyDown={onKeyDown}
121-
disabled={disabled}
135+
disabled={disabled || readOnly}
122136
{...additionalProps}
123137
/>
124138
}
@@ -135,7 +149,7 @@ export default function SelectableCard(props) {
135149
onBlur={onBlur}
136150
onClick={onClick}
137151
onKeyDown={onKeyDown}
138-
disabled={disabled}
152+
disabled={disabled || readOnly}
139153
{...additionalProps}
140154
/>
141155
}

0 commit comments

Comments
 (0)