Single select question radios (#965)
* fix(ui): make radios not jump around upon state change * fix(ui): use radios for single-select questions instead of checkboxes
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { RiArrowRightSLine, RiCheckLine, RiCloseLine, RiEditLine, RiListCheck3, RiQuestionLine } from '@remixicon/react';
|
import { RiArrowRightSLine, RiCheckLine, RiCloseLine, RiEditLine, RiListCheck3, RiQuestionLine } from '@remixicon/react';
|
||||||
import { Checkbox } from '@/components/ui/checkbox';
|
import { Checkbox } from '@/components/ui/checkbox';
|
||||||
|
import { Radio } from '@/components/ui/radio';
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import type { QuestionRequest } from '@/types/question';
|
import type { QuestionRequest } from '@/types/question';
|
||||||
@@ -295,11 +296,19 @@ export const QuestionCard: React.FC<QuestionCardProps> = ({ question }) => {
|
|||||||
>
|
>
|
||||||
<div className="flex items-start gap-2">
|
<div className="flex items-start gap-2">
|
||||||
<div className="mt-0.5 shrink-0">
|
<div className="mt-0.5 shrink-0">
|
||||||
<Checkbox
|
{isMultiple ? (
|
||||||
checked={selected}
|
<Checkbox
|
||||||
onChange={() => handleToggleOption(option.label)}
|
checked={selected}
|
||||||
disabled={isResponding}
|
onChange={() => handleToggleOption(option.label)}
|
||||||
/>
|
disabled={isResponding}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Radio
|
||||||
|
checked={selected}
|
||||||
|
onChange={() => handleToggleOption(option.label)}
|
||||||
|
disabled={isResponding}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
|
|||||||
@@ -62,15 +62,14 @@ export const Radio = React.memo<RadioProps>(function Radio({
|
|||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{checked ? (
|
<span
|
||||||
<span
|
aria-hidden
|
||||||
aria-hidden
|
className={cn(
|
||||||
className={cn(
|
'block h-[5px] w-[5px] rounded-full bg-white',
|
||||||
'block h-[5px] w-[5px] rounded-full bg-white',
|
!checked && 'opacity-0',
|
||||||
iconClassName,
|
iconClassName,
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
) : null}
|
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user