:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(phai): animate the custom answer reveal in the option selector (#99488)
Georgiy Tarasov97b428f4ad51
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 5f612a692000..bed87fc68074 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -5712,6 +5712,22 @@ snapshots:hash: v1.k794b7964.4ca1129988e8d505656c9b1f1d88398516fdb24c8ffbdabab43251369514b1e6.0jyOb_I1ghN1euG9Pq-PrpA2WhttqN8WfGn2NZvAZ1gproducts-posthog-ai-onboardingtakeover--start-step--light:hash: v1.k794b7964.d1fadd3c1c5f4734cf0ae54b7ddc1f64e351cbd0ef1e7b16b78968f98ad51a44.1u2R4G2yaaKLW_puoLCQrIIPiZcZYN6UMWWziknTITk+ products-posthog-ai-optionselector--custom-answer-open--dark:+ hash: v1.k794b7964.0fb8985f146f10b0f2d2e8e173c1b305b85ab164bd64d78aba25ca5ca38ef996.wfmmsk1cFF7HZebXlwOqc72p9YMCNT68zGklxTc5XhM+ products-posthog-ai-optionselector--custom-answer-open--light:+ hash: v1.k794b7964.5f65f02245f6394d84462491fec6e3908a950ffd858a479087b16043e84158b0.GKtD9N7W9Kzi75SbsPU7vfU0JNzl90cudA2nI2NzkgQ+ products-posthog-ai-optionselector--default--dark:+ hash: v1.k794b7964.320cb97623702ed32e7c6cf94a85010ae152c32d234102d1092c9633b0e163f6.hZMXYAwQCbQvHu2T2950pLJ-ybQ50dvZfZWjYNMWia0+ products-posthog-ai-optionselector--default--light:+ hash: v1.k794b7964.81dd05e1641e0b6fbff075823dc1dbce1dc3c1647d3718fe073606b0a586d507.r6xROTG-A0pvuRShovtQdtS3gebJyNn7SCmJiwUHjow+ products-posthog-ai-optionselector--no-descriptions--dark:+ hash: v1.k794b7964.a2f17679b586a884214c9f80f7be7022abe40006a5b05d4382297719f05e9b97.Q9pepq3rV6Dl02-X_79umoDDcydZ0LzKORoJBAMF3t8+ products-posthog-ai-optionselector--no-descriptions--light:+ hash: v1.k794b7964.73e156ee8d61ae4f8daa32f7fe1b7d4a11cef6056df4ef926cde18dc92e23d96.4c3SvI-f3tUMliR0EnuwuFO_h7yyyBICd8c4rBRoB9A+ products-posthog-ai-optionselector--with-skip--dark:+ hash: v1.k794b7964.9588d58bd88ada8f33df79fff5f4bc2d63b8d92b36d5d618bae5c0321308db56.mZM2HSmIFYWocLSCkCdXUDp9XeE5yjsEpHgDzvOE1S8+ products-posthog-ai-optionselector--with-skip--light:+ hash: v1.k794b7964.3e3088b0a9011240d1ea0408e7a00e93c45f6df467b0de5237b668ccc58b49d1.C0sUxwpoEuyYD9BM0daSWe9Y_Cfavx5NcMCT-znQWcwproducts-posthog-ai-permissioninput--matching-configuration--dark:hash: v1.k794b7964.be1eb7f0d99c67d743ea7fbc6ed8b4e0aefa7b561d30ae83b27546225b1a7703.08vwdgLYXwvFBF_mzK2cuSlZDQkpBLRDhRQY9dENK7Iproducts-posthog-ai-permissioninput--matching-configuration--light:diff --git a/products/posthog_ai/frontend/components/OptionSelector.stories.tsx b/products/posthog_ai/frontend/components/OptionSelector.stories.tsxnew file mode 100644index 000000000000..a14d01442eb5--- /dev/null+++ b/products/posthog_ai/frontend/components/OptionSelector.stories.tsx@@ -0,0 +1,50 @@+import type { Meta, StoryObj } from '@storybook/react'++import { OptionSelector } from './OptionSelector'++const meta: Meta<typeof OptionSelector> = {+ title: 'Products/PostHog AI/OptionSelector',+ component: OptionSelector,+ // The global `^on[A-Z].*` action inference would inject an `onSkip` handler, which keeps the footer open.+ parameters: { actions: { argTypesRegex: null } },+ args: {+ options: [+ { label: 'Product analytics', value: 'Product analytics', description: 'Track product metrics and KPIs' },+ { label: 'Session replay', value: 'Session replay', description: 'Watch how people use the product' },+ { label: 'Feature flags', value: 'Feature flags' },+ ],+ onSelect: () => {},+ allowCustom: true,+ customPlaceholder: 'Type your answer...',+ },+ decorators: [+ (Story) => (+ <div className="w-128 border rounded p-3">+ <Story />+ </div>+ ),+ ],+}+export default meta++type Story = StoryObj<typeof meta>++export const Default: Story = {}++export const CustomAnswerOpen: Story = {+ args: { selectedValue: 'Something else', initialCustomValue: 'Something else' },+}++export const WithSkip: Story = {+ args: { onSkip: () => {} },+}++export const NoDescriptions: Story = {+ args: {+ options: [+ { label: 'Weekly', value: 'Weekly' },+ { label: 'Monthly', value: 'Monthly' },+ { label: 'Quarterly', value: 'Quarterly' },+ ],+ },+}diff --git a/products/posthog_ai/frontend/components/OptionSelector.tsx b/products/posthog_ai/frontend/components/OptionSelector.tsxindex 5febfd704163..e4bd05e7e04e 100644--- a/products/posthog_ai/frontend/components/OptionSelector.tsx+++ b/products/posthog_ai/frontend/components/OptionSelector.tsx@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react'import { LemonButton, LemonInput, Spinner } from '@posthog/lemon-ui'+import { CollapsiblePrimitive, CollapsiblePrimitiveContent } from 'lib/ui/Collapsible/lib/CollapsiblePrimitive'import { cn } from 'lib/utils/css-classes'export interface Option {@@ -95,6 +96,11 @@ export function OptionSelector({}, [options, onSelect, allowCustom, disabled, loading, showCustomInput])const noDescriptions = options.every((o) => !o.description)+ const footerOpen = !!onSkip || showCustomInput+ // Without a skip button the submit button is the panel's only content. Base UI measures the closing+ // height after React commits, so if the button unmounted in the same render the row would snap to+ // its padding before it slides shut. Keep it mounted for as long as the panel is.+ const showSubmit = showCustomInput || !onSkipconst handleCustomSubmit = (): void => {if (!customInput.trim()) {@@ -117,89 +123,99 @@ export function OptionSelector({}return (- <div- className={cn('flex flex-col gap-1.5', {- // When there are no descriptions, reduce the gap between options to 0.5- 'gap-0.5': noDescriptions,- })}- >- <div className="flex flex-col gap-2 font-medium">- {options.map((o) => (- <label- key={o.value}- className="grid items-center gap-x-2 grid-cols-[min-content_auto] text-sm cursor-pointer"- onClick={(e) => {- e.preventDefault()- if (selectedValue === o.value) {- onSelect(null)- } else {- setUserWantsCustomMode(false)- onSelect(o.value)- }- }}- >+ <CollapsiblePrimitive open={footerOpen} className="flex flex-col">+ <div+ className={cn('flex flex-col gap-1.5', {+ // When there are no descriptions, reduce the gap between options to 0.5+ 'gap-0.5': noDescriptions,+ })}+ >+ <div className="flex flex-col gap-2 font-medium">+ {options.map((o) => (+ <label+ key={o.value}+ className="grid items-center gap-x-2 grid-cols-[min-content_auto] text-sm cursor-pointer"+ onClick={(e) => {+ e.preventDefault()+ if (selectedValue === o.value) {+ onSelect(null)+ } else {+ setUserWantsCustomMode(false)+ onSelect(o.value)+ }+ }}+ >+ <input+ type="radio"+ className="cursor-pointer"+ checked={selectedValue === o.value && !showCustomInput}+ onChange={() => {}}+ />+ <span>{o.label}</span>+ {o.description && (+ <div className="text-secondary font-normal row-start-2 col-start-2 text-pretty text-xs">+ {o.description}+ </div>+ )}+ </label>+ ))}+ </div>++ {allowCustom && (+ <label className="grid items-center gap-x-2 grid-cols-[min-content_auto] text-sm font-medium cursor-pointer"><inputtype="radio"className="cursor-pointer"- checked={selectedValue === o.value && !showCustomInput}- onChange={() => {}}+ checked={showCustomInput}+ onChange={() => {+ setUserWantsCustomMode(true)+ }}+ value="custom"/>- <span>{o.label}</span>- {o.description && (- <div className="text-secondary font-normal row-start-2 col-start-2 text-pretty text-xs">- {o.description}- </div>+ {showCustomInput ? (+ <LemonInput+ className="starting:opacity-0 opacity-100 transition-[opacity] duration-150 motion-reduce:transition-none"+ placeholder={customPlaceholder}+ fullWidth+ size="small"+ value={customInput}+ onChange={setCustomInput}+ onPressEnter={handleCustomSubmit}+ autoFocus={true}+ />+ ) : (+ <span className="my-1.5">Explain what you'd like instead.</span>)}</label>- ))}+ )}</div>-- {allowCustom && (- <label className="grid items-center gap-x-2 grid-cols-[min-content_auto] text-sm font-medium cursor-pointer">- <input- type="radio"- className="cursor-pointer"- checked={showCustomInput}- onChange={() => {- setUserWantsCustomMode(true)- }}- value="custom"- />- {showCustomInput ? (- <LemonInput- placeholder={customPlaceholder}- fullWidth- size="small"- value={customInput}- onChange={setCustomInput}- onPressEnter={handleCustomSubmit}- autoFocus={true}- />- ) : (- <span className="my-1.5">Explain what you'd like instead.</span>- )}- </label>- )}- {(onSkip || showCustomInput) && (- <div className="flex items-center justify-between gap-2 pt-2">- {onSkip && (- <LemonButton type="secondary" size="small" onClick={onSkip}>- Skip question- </LemonButton>- )}- {showCustomInput && (- <LemonButton- type="primary"- size="small"- disabledReason={!customInput.trim() ? 'Please type a response' : undefined}- onClick={handleCustomSubmit}- className="ml-auto"- >- {submitLabel}- </LemonButton>- )}- </div>+ {(allowCustom || footerOpen) && (+ <CollapsiblePrimitiveContent className="transition-[height,opacity] duration-150 ease-out opacity-100 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0 motion-reduce:transition-none">+ <div+ className={cn('flex items-center justify-between gap-2 pt-3.5', {+ 'pt-2.5': noDescriptions,+ })}+ >+ {onSkip && (+ <LemonButton type="secondary" size="small" onClick={onSkip}>+ Skip question+ </LemonButton>+ )}+ {showSubmit && (+ <div className="ml-auto starting:opacity-0 opacity-100 transition-[opacity] duration-150 motion-reduce:transition-none">+ <LemonButton+ type="primary"+ size="small"+ disabledReason={!customInput.trim() ? 'Please type a response' : undefined}+ onClick={handleCustomSubmit}+ >+ {submitLabel}+ </LemonButton>+ </div>+ )}+ </div>+ </CollapsiblePrimitiveContent>)}- </div>+ </CollapsiblePrimitive>)}