: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
feat(lemon-ui): add opt-in showErrorsOnTouch to LemonFormDialog (#70095)
Thiago Salvatore79e362f74cda
diff --git a/frontend/src/lib/lemon-ui/LemonDialog/LemonDialog.tsx b/frontend/src/lib/lemon-ui/LemonDialog/LemonDialog.tsxindex 434256e88a46..8506f6c67e0f 100644--- a/frontend/src/lib/lemon-ui/LemonDialog/LemonDialog.tsx+++ b/frontend/src/lib/lemon-ui/LemonDialog/LemonDialog.tsx@@ -186,9 +186,10 @@ export const LemonFormDialog = ({content,primaryButtonProps,dialogKey,+ showErrorsOnTouch,...props}: LemonFormDialogProps): JSX.Element => {- const logicProps = { errors, dialogKey }+ const logicProps = { errors, dialogKey, showErrorsOnTouch }const logic = lemonDialogLogic(logicProps)const { form, isFormValid, formValidationErrors } = useValues(logic)const { setFormValues } = useActions(logic)diff --git a/frontend/src/lib/lemon-ui/LemonDialog/lemonDialogLogic.test.ts b/frontend/src/lib/lemon-ui/LemonDialog/lemonDialogLogic.test.tsindex 1f25a3ba3026..e235b8de34a1 100644--- a/frontend/src/lib/lemon-ui/LemonDialog/lemonDialogLogic.test.ts+++ b/frontend/src/lib/lemon-ui/LemonDialog/lemonDialogLogic.test.ts@@ -32,6 +32,44 @@ describe('lemonDialogLogic', () => {saveView.unmount()})+ it('with showErrorsOnTouch, exposes field errors only after the field is touched, and clears once fixed', () => {+ const logic = lemonDialogLogic({+ dialogKey: 'touch-gated',+ showErrorsOnTouch: true,+ errors: { name: (value: string) => (!value ? 'Name is required' : undefined) },+ })+ logic.mount()+ logic.actions.setFormValues({ name: '' })++ // The form knows it's invalid, but the inline error stays hidden until interaction.+ expect(logic.values.isFormValid).toBe(false)+ expect(logic.values.formErrors).toEqual({})++ logic.actions.touchFormField('name')+ expect(logic.values.formErrors).toEqual({ name: 'Name is required' })++ logic.actions.setFormValues({ name: 'valid' })+ expect(logic.values.formErrors).toEqual({})++ logic.unmount()+ })++ it('without showErrorsOnTouch, keeps inline field errors hidden even after a field is touched', () => {+ const logic = lemonDialogLogic({+ dialogKey: 'not-touch-gated',+ errors: { name: (value: string) => (!value ? 'Name is required' : undefined) },+ })+ logic.mount()+ logic.actions.setFormValues({ name: '' })+ logic.actions.touchFormField('name')++ // Default behavior for every other openForm caller: no inline errors, only the disabled submit.+ expect(logic.values.isFormValid).toBe(false)+ expect(logic.values.formErrors).toEqual({})++ logic.unmount()+ })+it('shares state when no key is provided, falling back to a single default instance', () => {const first = lemonDialogLogic({ errors: {} })first.mount()diff --git a/frontend/src/lib/lemon-ui/LemonDialog/lemonDialogLogic.ts b/frontend/src/lib/lemon-ui/LemonDialog/lemonDialogLogic.tsindex 77ec4655b56f..28a77bf58d81 100644--- a/frontend/src/lib/lemon-ui/LemonDialog/lemonDialogLogic.ts+++ b/frontend/src/lib/lemon-ui/LemonDialog/lemonDialogLogic.ts@@ -7,6 +7,8 @@ export type LemonDialogFormPropsType = {errors?: Record<string, (value: string) => string | undefined>/** Unique key that isolates this dialog's form state from other open dialogs. */dialogKey?: string+ /** Surface field errors inline once a field is touched, instead of only via the submit button tooltip. */+ showErrorsOnTouch?: boolean}export const lemonDialogLogic = kea<lemonDialogLogicType>([@@ -15,6 +17,7 @@ export const lemonDialogLogic = kea<lemonDialogLogicType>([path((k) => ['components', 'lemon-dialog', 'lemonDialogLogic', k]),forms(({ props }) => ({form: {+ options: { showErrorsOnTouch: props.showErrorsOnTouch ?? false },defaults: {} as Record<string, string>,errors: (values: Record<string, string>) => {const entries = Object.entries(props.errors || []).map(([key, valueOf]) => {