Skip to content

Commit e5a3201

Browse files
committed
add selection resetting
1 parent b7147f9 commit e5a3201

1 file changed

Lines changed: 35 additions & 41 deletions

File tree

src/public/viz-guardrails/MetadataRankingTask.tsx

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -99,52 +99,46 @@ export function MetadataRankingTask({ parameters, setAnswer }: any) {
9999
>
100100
<Box style={{ position: 'relative' }}>
101101
<Box style={{ position: 'absolute', top: 0, left: 8 }}>
102-
<label
102+
<div
103+
role="button"
104+
tabIndex={0}
105+
aria-pressed={selectedGuardrail === guardrail}
106+
onClick={() => {
107+
if (selectedGuardrail === guardrail) {
108+
setSelectedGuardrail(null);
109+
setAnswer?.({ status: false, answers: {} });
110+
} else {
111+
setSelectedGuardrail(guardrail);
112+
setAnswer?.({ status: true, answers: { condition: guardrail } });
113+
}
114+
}}
115+
onKeyDown={(e) => {
116+
if (e.key === 'Enter' || e.key === ' ') {
117+
e.preventDefault();
118+
if (selectedGuardrail === guardrail) {
119+
setSelectedGuardrail(null);
120+
setAnswer?.({ status: false, answers: {} });
121+
} else {
122+
setSelectedGuardrail(guardrail);
123+
setAnswer?.({ status: true, answers: { condition: guardrail } });
124+
}
125+
}
126+
}}
103127
style={{
104-
display: 'inline-flex',
105-
alignItems: 'center',
128+
display: 'inline-block',
129+
padding: '6px 10px',
130+
borderRadius: 9999,
131+
background: selectedGuardrail === guardrail ? '#1c7ed6' : '#e7f5ff',
132+
color: selectedGuardrail === guardrail ? '#fff' : '#1864ab',
133+
fontSize: 13,
134+
fontWeight: 700,
135+
boxShadow: selectedGuardrail === guardrail ? '0 2px 6px rgba(28,126,214,0.35)' : 'none',
106136
cursor: 'pointer',
107137
userSelect: 'none',
108138
}}
109139
>
110-
<input
111-
type="radio"
112-
name="favorite-guardrail"
113-
value={guardrail}
114-
checked={selectedGuardrail === guardrail}
115-
onChange={() => {
116-
setSelectedGuardrail(guardrail);
117-
setAnswer?.({ status: true, answers: { condition: guardrail } });
118-
}}
119-
style={{
120-
// visually hide native radio but keep it accessible
121-
position: 'absolute',
122-
opacity: 0,
123-
width: 1,
124-
height: 1,
125-
overflow: 'hidden',
126-
clip: 'rect(0 0 0 0)',
127-
whiteSpace: 'nowrap',
128-
border: 0,
129-
}}
130-
/>
131-
<span
132-
role="button"
133-
aria-pressed={selectedGuardrail === guardrail}
134-
style={{
135-
display: 'inline-block',
136-
padding: '6px 10px',
137-
borderRadius: 9999,
138-
background: selectedGuardrail === guardrail ? '#1c7ed6' : '#e7f5ff',
139-
color: selectedGuardrail === guardrail ? '#fff' : '#1864ab',
140-
fontSize: 13,
141-
fontWeight: 700,
142-
boxShadow: selectedGuardrail === guardrail ? '0 2px 6px rgba(28,126,214,0.35)' : 'none',
143-
}}
144-
>
145-
{selectedGuardrail === guardrail ? 'Selected' : 'Select'}
146-
</span>
147-
</label>
140+
{selectedGuardrail === guardrail ? 'Selected' : 'Select'}
141+
</div>
148142
</Box>
149143
<Text fw={700} ta="center" mb={4} fz="lg">
150144
{label}

0 commit comments

Comments
 (0)