diff --git a/apps/web/app/(app)/environments/[environmentId]/integrations/airtable/components/AddIntegrationModal.tsx b/apps/web/app/(app)/environments/[environmentId]/integrations/airtable/components/AddIntegrationModal.tsx index 10c4294e5f..73192f620c 100644 --- a/apps/web/app/(app)/environments/[environmentId]/integrations/airtable/components/AddIntegrationModal.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/integrations/airtable/components/AddIntegrationModal.tsx @@ -291,7 +291,7 @@ export const AddIntegrationModal = ({
-
+
{replaceHeadlineRecall(selectedSurvey, "default", attributeClasses)?.questions.map( (question) => ( diff --git a/apps/web/app/(app)/environments/[environmentId]/integrations/google-sheets/components/AddIntegrationModal.tsx b/apps/web/app/(app)/environments/[environmentId]/integrations/google-sheets/components/AddIntegrationModal.tsx index 114c32d91b..83a20c1cef 100644 --- a/apps/web/app/(app)/environments/[environmentId]/integrations/google-sheets/components/AddIntegrationModal.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/integrations/google-sheets/components/AddIntegrationModal.tsx @@ -229,7 +229,7 @@ export const AddIntegrationModal = ({
-
+
{replaceHeadlineRecall(selectedSurvey, "default", attributeClasses)?.questions.map( (question) => ( diff --git a/apps/web/app/(app)/environments/[environmentId]/integrations/slack/components/AddChannelMappingModal.tsx b/apps/web/app/(app)/environments/[environmentId]/integrations/slack/components/AddChannelMappingModal.tsx index 1395b58690..1d7e976df7 100644 --- a/apps/web/app/(app)/environments/[environmentId]/integrations/slack/components/AddChannelMappingModal.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/integrations/slack/components/AddChannelMappingModal.tsx @@ -231,7 +231,7 @@ export const AddChannelMappingModal = ({
-
+
{replaceHeadlineRecall(selectedSurvey, "default", attributeClasses)?.questions?.map( (question) => ( diff --git a/packages/surveys/src/components/buttons/SubmitButton.tsx b/packages/surveys/src/components/buttons/SubmitButton.tsx index b9a66e217d..20d48ac8eb 100644 --- a/packages/surveys/src/components/buttons/SubmitButton.tsx +++ b/packages/surveys/src/components/buttons/SubmitButton.tsx @@ -1,21 +1,21 @@ +import { JSX } from "preact"; import { useCallback } from "preact/hooks"; -interface SubmitButtonProps { +interface SubmitButtonProps extends JSX.HTMLAttributes { buttonLabel: string | undefined; isLastQuestion: boolean; - onClick?: () => void; focus?: boolean; - tabIndex?: number; - type?: "submit" | "button"; } export const SubmitButton = ({ buttonLabel, isLastQuestion, - onClick = () => {}, tabIndex = 1, focus = false, - type = "submit", + onClick, + disabled, + type, + ...props }: SubmitButtonProps) => { const buttonRef = useCallback( (currentButton: HTMLButtonElement | null) => { @@ -30,13 +30,15 @@ export const SubmitButton = ({ return ( ); diff --git a/packages/surveys/src/components/general/ProgressBar.tsx b/packages/surveys/src/components/general/ProgressBar.tsx index a65c5776bc..4351ef8398 100644 --- a/packages/surveys/src/components/general/ProgressBar.tsx +++ b/packages/surveys/src/components/general/ProgressBar.tsx @@ -29,5 +29,9 @@ export const ProgressBar = ({ survey, questionId }: ProgressBarProps) => { return survey.questions.map((_, index) => calculateProgress(index, survey.questions.length)); }, [calculateProgress, survey]); - return ; + return ( + + ); }; diff --git a/packages/surveys/src/components/general/Survey.tsx b/packages/surveys/src/components/general/Survey.tsx index 33d741d3f2..de95dfd86a 100644 --- a/packages/surveys/src/components/general/Survey.tsx +++ b/packages/surveys/src/components/general/Survey.tsx @@ -253,6 +253,7 @@ export const Survey = ({ if (questionIdx === -1) { return ( ); } else if (questionIdx === survey.questions.length) { return ( ); } else { @@ -291,6 +296,7 @@ export const Survey = ({ return ( question && ( { const media = imageUrl || videoUrl ? : null; const checkmark = ( @@ -51,6 +57,30 @@ export const ThankYouCard = ({
); + const handleSubmit = () => { + if (buttonLink) window.location.replace(buttonLink); + }; + + useEffect(() => { + const handleEnter = (e: KeyboardEvent) => { + if (e.key === "Enter") { + handleSubmit(); + } + }; + + if (isCurrent && survey.type === "link") { + document.addEventListener("keydown", handleEnter); + } else { + document.removeEventListener("keydown", handleEnter); + } + + return () => { + document.removeEventListener("keydown", handleEnter); + }; + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [isCurrent]); + return (
@@ -66,10 +96,7 @@ export const ThankYouCard = ({ buttonLabel={buttonLabel} isLastQuestion={false} focus={autoFocusEnabled} - onClick={() => { - if (!buttonLink) return; - window.location.replace(buttonLink); - }} + onClick={handleSubmit} />
)} diff --git a/packages/surveys/src/components/general/WelcomeCard.tsx b/packages/surveys/src/components/general/WelcomeCard.tsx index a58a014feb..dbf7317b5d 100644 --- a/packages/surveys/src/components/general/WelcomeCard.tsx +++ b/packages/surveys/src/components/general/WelcomeCard.tsx @@ -1,6 +1,7 @@ import { SubmitButton } from "@/components/buttons/SubmitButton"; import { ScrollableContainer } from "@/components/wrappers/ScrollableContainer"; import { calculateElementIdx } from "@/lib/utils"; +import { useEffect } from "preact/hooks"; import { getLocalizedValue } from "@formbricks/lib/i18n/utils"; import { TResponseData, TResponseTtc } from "@formbricks/types/responses"; import { TI18nString, TSurvey } from "@formbricks/types/surveys"; @@ -18,6 +19,7 @@ interface WelcomeCardProps { responseCount?: number; autoFocusEnabled: boolean; replaceRecallInfo: (text: string, responseData: TResponseData) => string; + isCurrent: boolean; } const TimerIcon = () => { @@ -68,6 +70,7 @@ export const WelcomeCard = ({ responseCount, autoFocusEnabled, replaceRecallInfo, + isCurrent, }: WelcomeCardProps) => { const calculateTimeToComplete = () => { let idx = calculateElementIdx(survey, 0); @@ -100,6 +103,30 @@ export const WelcomeCard = ({ const timeToFinish = survey.welcomeCard.timeToFinish; const showResponseCount = survey.welcomeCard.showResponseCount; + const handleSubmit = () => { + onSubmit({ ["welcomeCard"]: "clicked" }, {}); + }; + + useEffect(() => { + const handleEnter = (e: KeyboardEvent) => { + if (e.key === "Enter") { + handleSubmit(); + } + }; + + if (isCurrent && survey.type === "link") { + document.addEventListener("keydown", handleEnter); + } else { + document.removeEventListener("keydown", handleEnter); + } + + return () => { + document.removeEventListener("keydown", handleEnter); + }; + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [isCurrent]); + return (
@@ -124,10 +151,9 @@ export const WelcomeCard = ({ buttonLabel={getLocalizedValue(buttonLabel, languageCode)} isLastQuestion={false} focus={autoFocusEnabled} - onClick={() => { - onSubmit({ ["welcomeCard"]: "clicked" }, {}); - }} + onClick={handleSubmit} type="button" + onKeyDown={(e) => e.key === "Enter" && e.preventDefault()} />
diff --git a/packages/ui/DropdownSelector/index.tsx b/packages/ui/DropdownSelector/index.tsx index 410a93c662..335601f06f 100644 --- a/packages/ui/DropdownSelector/index.tsx +++ b/packages/ui/DropdownSelector/index.tsx @@ -50,7 +50,7 @@ export const DropdownSelector = ({ {!disabled && ( {items .sort((a, b) => a.name?.localeCompare(b.name))