()
| 665 | const checked = currentDraft.selected.includes(opt.label); |
| 666 | |
| 667 | const toggle = () => { |
| 668 | const isSelecting = !checked; |
| 669 | |
| 670 | setDraftAnswers((prev) => { |
| 671 | const draft = prev[currentQuestion.question] ?? { |
| 672 | selected: [], |
| 673 | otherText: "", |
| 674 | }; |
| 675 | |
| 676 | if (currentQuestion.multiSelect) { |
| 677 | // Multi-select: toggle this option |
| 678 | const selected = new Set(draft.selected); |
| 679 | if (selected.has(opt.label)) { |
| 680 | selected.delete(opt.label); |
| 681 | } else { |
| 682 | selected.add(opt.label); |
| 683 | } |
| 684 | return { |
| 685 | ...prev, |
| 686 | [currentQuestion.question]: { |
| 687 | ...draft, |
| 688 | selected: Array.from(selected), |
| 689 | }, |
| 690 | }; |
| 691 | } else { |
| 692 | // Single-select: replace selection (clear otherText if not Other) |
| 693 | return { |
| 694 | ...prev, |
| 695 | [currentQuestion.question]: { |
| 696 | selected: checked ? [] : [opt.label], |
| 697 | otherText: opt.label === OTHER_VALUE ? draft.otherText : "", |
| 698 | }, |
| 699 | }; |
| 700 | } |
| 701 | }); |
| 702 | |
| 703 | // For single-select questions, auto-advance *only* when the user selects |
| 704 | // a non-Other option (avoid useEffect auto-advance that breaks back-nav). |
| 705 | if ( |
| 706 | !currentQuestion.multiSelect && |
| 707 | isSelecting && |
| 708 | opt.label !== OTHER_VALUE |
| 709 | ) { |
| 710 | setActiveIndex((idx) => idx + 1); |
| 711 | } |
| 712 | }; |
| 713 | |
| 714 | return ( |
| 715 | <div |
no test coverage detected