Skip to content

Commit 3dda655

Browse files
authored
fix: Wrap disable html validation toggle in Boolean (#219)
* fix: add wrapper to force boolean to undefined * chore: forgot changeset
1 parent 968bf52 commit 3dda655

File tree

15 files changed

+48
-41
lines changed

15 files changed

+48
-41
lines changed

.changeset/new-wolves-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@formwerk/core': patch
3+
---
4+
5+
Change type for disableHtmlValidation to Boolean to prevent Vue compiling undefined to false

packages/core/src/types/common.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,3 @@ export type MaybeGetter<T> = T | Getter<T>;
107107

108108
// eslint-disable-next-line @typescript-eslint/no-explicit-any
109109
export type DangerousAny = any;
110-
111-
export type TransparentWrapper<T> = T;

packages/core/src/useCheckbox/useCheckbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
Reactivify,
99
RovingTabIndex,
1010
StandardSchema,
11-
TransparentWrapper,
1211
} from '../types';
1312
import { useLabel, useErrorMessage } from '../a11y';
1413
import { CheckboxGroupContext, CheckboxGroupKey } from './useCheckboxGroup';
@@ -80,7 +79,8 @@ export interface CheckboxProps<TValue = boolean> {
8079
/**
8180
* Whether HTML5 validation should be disabled for this checkbox.
8281
*/
83-
disableHtmlValidation?: TransparentWrapper<boolean>;
82+
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
83+
disableHtmlValidation?: Boolean;
8484
}
8585

8686
export interface CheckboxDomInputProps extends AriaLabelableProps, InputBaseAttributes {

packages/core/src/useCheckbox/useCheckboxGroup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
import { useLocale } from '../i18n';
2525
import { FormField, useFormField, exposeField } from '../useFormField';
2626
import { FieldTypePrefixes } from '../constants';
27-
import { TransparentWrapper } from '../types';
2827

2928
export type CheckboxGroupValue<TCheckbox> = TCheckbox[];
3029

@@ -108,7 +107,8 @@ export interface CheckboxGroupProps<TCheckbox = unknown> {
108107
/**
109108
* Whether HTML5 validation should be disabled for this checkbox group.
110109
*/
111-
disableHtmlValidation?: TransparentWrapper<boolean>;
110+
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
111+
disableHtmlValidation?: Boolean;
112112
}
113113

114114
interface CheckboxGroupDomProps extends AriaLabelableProps, AriaDescribableProps, AriaValidatableProps {

packages/core/src/useComboBox/useComboBox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { useInputValidity } from '../validation';
2020
import { FilterFn } from '../collections';
2121
import { useControlButtonProps } from '../helpers/useControlButtonProps';
2222
import { registerField } from '@formwerk/devtools';
23-
import { TransparentWrapper } from '../types';
2423

2524
export interface ComboBoxProps<TOption, TValue = TOption> {
2625
/**
@@ -81,7 +80,8 @@ export interface ComboBoxProps<TOption, TValue = TOption> {
8180
/**
8281
* Whether to disable HTML5 validation.
8382
*/
84-
disableHtmlValidation?: TransparentWrapper<boolean>;
83+
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
84+
disableHtmlValidation?: Boolean;
8585

8686
/**
8787
* Whether to open the popup when the input is focused.

packages/core/src/useForm/useForm.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { inject, InjectionKey, MaybeRefOrGetter, onMounted, provide, reactive, readonly, Ref, ref } from 'vue';
22
import type { StandardSchemaV1 } from '@standard-schema/spec';
33
import { registerForm } from '@formwerk/devtools';
4-
import { cloneDeep, useUniqId, warn } from '../utils/common';
4+
import { cloneDeep, toPrimitiveBooleanValue, useUniqId, warn } from '../utils/common';
55
import {
66
FormObject,
77
MaybeAsync,
@@ -28,7 +28,6 @@ import { FieldTypePrefixes } from '../constants';
2828
import { appendToFormData, clearFormData } from '../utils/formData';
2929
import { Arrayable, PartialDeep } from 'type-fest';
3030
import { createDisabledContext } from '../helpers/createDisabledContext';
31-
import { TransparentWrapper } from '../types';
3231

3332
interface _FormProps<TInput extends FormObject> {
3433
/**
@@ -49,7 +48,8 @@ interface _FormProps<TInput extends FormObject> {
4948
/**
5049
* Whether HTML5 validation should be disabled for this form.
5150
*/
52-
disableHtmlValidation?: TransparentWrapper<boolean>;
51+
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
52+
disableHtmlValidation?: Boolean;
5353

5454
/**
5555
* Whether the form is disabled.
@@ -262,7 +262,8 @@ export function useForm<
262262

263263
const id = props?.id || useUniqId(FieldTypePrefixes.Form);
264264
const isDisabled = createDisabledContext(props?.disabled);
265-
const isHtmlValidationDisabled = () => props?.disableHtmlValidation ?? getConfig().disableHtmlValidation;
265+
const isHtmlValidationDisabled = () =>
266+
toPrimitiveBooleanValue(props?.disableHtmlValidation) ?? getConfig().disableHtmlValidation;
266267
const values = reactive(cloneDeep(valuesSnapshot.originals.value)) as PartialDeep<TResolvedInput>;
267268
const touched = reactive(cloneDeep(touchedSnapshot.originals.value)) as TouchedSchema<TResolvedInput>;
268269
const dirty = reactive(cloneDeep(dirtySnapshot.originals.value)) as DirtySchema<TResolvedInput>;

packages/core/src/useFormGroup/useFormGroup.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ import {
99
StandardSchema,
1010
ValidationResult,
1111
} from '../types';
12-
import { normalizeProps, useUniqId, warn, useCaptureProps } from '../utils/common';
12+
import { normalizeProps, useUniqId, warn, useCaptureProps, toPrimitiveBooleanValue } from '../utils/common';
1313
import { FormKey } from '../useForm';
1414
import { useValidationProvider } from '../validation/useValidationProvider';
1515
import { FormValidationMode } from '../useForm/formContext';
1616
import { prefixPath as _prefixPath } from '../utils/path';
1717
import { getConfig } from '../config';
1818
import { createPathPrefixer, usePathPrefixer } from '../helpers/usePathPrefixer';
1919
import { createDisabledContext } from '../helpers/createDisabledContext';
20-
import { TransparentWrapper } from '../types';
2120

2221
export interface FormGroupProps<TInput extends FormObject = FormObject, TOutput extends FormObject = TInput> {
2322
/**
@@ -43,7 +42,8 @@ export interface FormGroupProps<TInput extends FormObject = FormObject, TOutput
4342
/**
4443
* Whether HTML5 validation should be disabled for this form group.
4544
*/
46-
disableHtmlValidation?: TransparentWrapper<boolean>;
45+
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
46+
disableHtmlValidation?: Boolean;
4747
}
4848

4949
interface GroupProps extends AriaLabelableProps {
@@ -84,7 +84,9 @@ export function useFormGroup<TInput extends FormObject = FormObject, TOutput ext
8484
const parentGroup = inject(FormGroupKey, null);
8585
const isDisabled = createDisabledContext(props.disabled);
8686
const isHtmlValidationDisabled = () =>
87-
toValue(props.disableHtmlValidation) ?? form?.isHtmlValidationDisabled() ?? getConfig().disableHtmlValidation;
87+
toPrimitiveBooleanValue(props.disableHtmlValidation) ??
88+
form?.isHtmlValidationDisabled() ??
89+
getConfig().disableHtmlValidation;
8890
const { validate, onValidationDispatch, defineValidationRequest, onValidationDone, dispatchValidateDone } =
8991
useValidationProvider({
9092
getValues: () => getValue(),

packages/core/src/useNumberField/useNumberField.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { exposeField, useFormField } from '../useFormField';
2727
import { FieldTypePrefixes } from '../constants';
2828
import { useEventListener } from '../helpers/useEventListener';
2929
import { registerField } from '@formwerk/devtools';
30-
import { TransparentWrapper } from '../types';
3130

3231
export interface NumberInputDOMAttributes {
3332
name?: string;
@@ -136,7 +135,8 @@ export interface NumberFieldProps {
136135
/**
137136
* Whether to disable HTML5 form validation.
138137
*/
139-
disableHtmlValidation?: TransparentWrapper<boolean>;
138+
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
139+
disableHtmlValidation?: Boolean;
140140
}
141141

142142
export function useNumberField(_props: Reactivify<NumberFieldProps, 'schema'>) {

packages/core/src/useOtpField/useOtpField.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { OtpSlotProps } from './useOtpSlot';
1010
import { registerField } from '@formwerk/devtools';
1111
import { DEFAULT_MASK, isValueAccepted } from './utils';
1212
import { blockEvent } from '../utils/events';
13-
import { TransparentWrapper } from '../types';
1413

1514
export interface OtpFieldProps {
1615
/**
@@ -76,7 +75,8 @@ export interface OtpFieldProps {
7675
/**
7776
* Whether to disable HTML validation.
7877
*/
79-
disableHtmlValidation?: TransparentWrapper<boolean>;
78+
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
79+
disableHtmlValidation?: Boolean;
8080

8181
/**
8282
* The prefix of the OTP field. If you prefix your codes with a character, you can set it here (e.g "G-").

packages/core/src/useRadio/useRadioGroup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
import { useLocale } from '../i18n';
2424
import { useFormField, exposeField } from '../useFormField';
2525
import { FieldTypePrefixes } from '../constants';
26-
import { TransparentWrapper } from '../types';
2726

2827
export interface RadioGroupContext<TValue> {
2928
name: string;
@@ -102,7 +101,8 @@ export interface RadioGroupProps<TValue = string> {
102101
/**
103102
* Whether to disable HTML5 form validation.
104103
*/
105-
disableHtmlValidation?: TransparentWrapper<boolean>;
104+
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
105+
disableHtmlValidation?: Boolean;
106106
}
107107

108108
interface RadioGroupDomProps extends AriaLabelableProps, AriaDescribableProps, AriaValidatableProps {

0 commit comments

Comments
 (0)