@@ -511,9 +511,15 @@ const ChoiceQuestionView: React.FC<ChoiceQuestionViewProps> = ({
511511} ) => {
512512 const keyMatchers = useKeyMatchers ( ) ;
513513 const isAlternateBuffer = useAlternateBuffer ( ) ;
514- const hasAll = question . multiSelect && ( question . options ?. length ?? 0 ) > 1 ;
514+
515+ const questionOptions = useMemo (
516+ ( ) => question . options ?? [ ] ,
517+ [ question . options ] ,
518+ ) ;
519+
520+ const showAllOption = question . multiSelect && questionOptions . length > 1 ;
515521 // Calculate total options including 'All' and 'Other' to ensure consistent numbering column width
516- const numOptions = ( question . options ?. length ?? 0 ) + ( hasAll ? 1 : 0 ) + 1 ;
522+ const numOptions = questionOptions . length + ( showAllOption ? 1 : 0 ) + 1 ;
517523 const numLen = String ( numOptions ) . length ;
518524 const radioWidth = 2 ; // "● "
519525 const numberWidth = numLen + 2 ; // e.g., "1. "
@@ -526,11 +532,6 @@ const ChoiceQuestionView: React.FC<ChoiceQuestionViewProps> = ({
526532
527533 const bufferWidth = availableWidth - horizontalPadding ;
528534
529- const questionOptions = useMemo (
530- ( ) => question . options ?? [ ] ,
531- [ question . options ] ,
532- ) ;
533-
534535 // Initialize state from initialAnswer if returning to a previously answered question
535536 const initialReducerState = useMemo ( ( ) : ChoiceQuestionState => {
536537 if ( ! initialAnswer ) {
@@ -725,7 +726,7 @@ const ChoiceQuestionView: React.FC<ChoiceQuestionViewProps> = ({
725726 ) ;
726727
727728 // Add 'All of the above' for multi-select
728- if ( question . multiSelect && questionOptions . length > 1 ) {
729+ if ( showAllOption ) {
729730 const allItem : OptionItem = {
730731 key : 'all' ,
731732 label : 'All of the above' ,
@@ -758,7 +759,7 @@ const ChoiceQuestionView: React.FC<ChoiceQuestionViewProps> = ({
758759 }
759760
760761 return list ;
761- } , [ questionOptions , question . multiSelect , customOptionText ] ) ;
762+ } , [ questionOptions , showAllOption , customOptionText , question . multiSelect ] ) ;
762763
763764 const handleHighlight = useCallback (
764765 ( itemValue : OptionItem ) => {
0 commit comments