From 2c4a28288d272b1389be6811090a794897fb5e02 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 6 Jun 2022 13:38:48 -0500 Subject: [PATCH] PollForm: autosuggest fix --- app/soapbox/features/compose/components/poll-form.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/soapbox/features/compose/components/poll-form.tsx b/app/soapbox/features/compose/components/poll-form.tsx index 040b904c7..0f8e87387 100644 --- a/app/soapbox/features/compose/components/poll-form.tsx +++ b/app/soapbox/features/compose/components/poll-form.tsx @@ -10,6 +10,8 @@ import IconButton from 'soapbox/components/icon_button'; import { HStack } from 'soapbox/components/ui'; import { useAppSelector } from 'soapbox/hooks'; +import type { AutoSuggestion } from 'soapbox/components/autosuggest_input'; + const messages = defineMessages({ option_placeholder: { id: 'compose_form.poll.option_placeholder', defaultMessage: 'Choice {number}' }, add_option: { id: 'compose_form.poll.add_option', defaultMessage: 'Add a choice' }, @@ -83,8 +85,11 @@ const Option = (props: IOption) => { const onSuggestionsFetchRequested = (token: string) => onFetchSuggestions(token); - const onSuggestionSelected = (tokenStart: number, token: string, value: string) => - props.onSuggestionSelected(tokenStart, token, value, ['poll', 'options', index]); + const onSuggestionSelected = (tokenStart: number, token: string | null, value: AutoSuggestion) => { + if (token && typeof value === 'string') { + props.onSuggestionSelected(tokenStart, token, value, ['poll', 'options', index]); + } + }; return (