Skip to content

Commit

Permalink
refactor: move useformfield to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Aug 13, 2024
1 parent b3810d6 commit 8f4697b
Show file tree
Hide file tree
Showing 18 changed files with 19 additions and 18 deletions.
1 change: 0 additions & 1 deletion packages/core/src/form/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './useForm';
export * from './useFormField';
2 changes: 1 addition & 1 deletion packages/core/src/form/useErrorDisplay.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderSetup } from '@test-utils/index';
import { useErrorDisplay } from './useErrorDisplay';
import { useFormField } from './useFormField';
import { useFormField } from '../useFormField';

test('displays field errors only if they are touched', async () => {
const { setErrors, isValid, errorMessage, displayError, setTouched } = await renderSetup(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/form/useErrorDisplay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormField } from './useFormField';
import { FormField } from '../useFormField';

export function useErrorDisplay(field: FormField<any>) {
function displayError(msg?: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/form/useForm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { flush, renderSetup } from '@test-utils/index';
import { useForm } from './useForm';
import { useFormField } from './useFormField';
import { useFormField } from '../useFormField';
import { Component, nextTick, Ref, ref } from 'vue';
import { useInputValidity } from '../validation/useInputValidity';
import { fireEvent, render, screen } from '@testing-library/vue';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/useCheckbox/useCheckbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isEqual, normalizeProps, useUniqId, withRefCapture } from '../utils/com
import { AriaLabelableProps, Reactivify, InputBaseAttributes, RovingTabIndex } from '../types';
import { useLabel } from '../a11y/useLabel';
import { CheckboxGroupContext, CheckboxGroupKey } from './useCheckboxGroup';
import { useFormField } from '../form/useFormField';
import { useFormField } from '../useFormField';
import { FieldTypePrefixes } from '../constants';

export interface CheckboxProps<TValue = string> {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/useCheckbox/useCheckboxGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../types';
import { useUniqId, createDescribedByProps, normalizeProps, isEqual } from '../utils/common';
import { useLocale } from '../i18n/useLocale';
import { useFormField } from '../form/useFormField';
import { useFormField } from '../useFormField';
import { FieldTypePrefixes } from '../constants';
import { useErrorDisplay } from '../form/useErrorDisplay';

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/useFormField/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useFormField';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderSetup } from '@test-utils/index';
import { useFormField } from './useFormField';
import { useForm } from './useForm';
import { useForm } from '../form/useForm';

test('it initializes the field value', async () => {
const { fieldValue } = await renderSetup(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
toValue,
watch,
} from 'vue';
import { FormContext, FormKey } from './useForm';
import { FormContext, FormKey } from '../form/useForm';
import { Arrayable, Getter } from '../types';
import { useSyncModel } from '../reactivity/useModelSync';
import { cloneDeep, isEqual, normalizeArrayable } from '../utils/common';
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/useFormGroup/useFormGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function useFormGroup<TInput extends FormObject = FormObject, TOutput ext

const ctx: FormGroupContext = {
prefixPath(path: string | undefined) {
return prefixPath(toValue(props.name), path);
return prefixGroupPath(toValue(props.name), path);
},
};

Expand Down Expand Up @@ -104,7 +104,7 @@ function createInlineFormGroupComponent({ groupProps, labelProps }: Reactivify<I
};
}

function prefixPath(prefix: string | undefined, path: string | undefined) {
function prefixGroupPath(prefix: string | undefined, path: string | undefined) {
if (!path) {
return path;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/useNumberField/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { useLabel } from '../a11y/useLabel';
import { useNumberParser } from '../i18n/useNumberParser';
import { useSpinButton } from '../useSpinButton';
import { useLocale } from '../i18n/useLocale';
import { useFormField } from '../form/useFormField';
import { useFormField } from '../useFormField';
import { FieldTypePrefixes } from '../constants';
import { useErrorDisplay } from '../form/useErrorDisplay';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/useRadio/useRadioGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../types';
import { useUniqId, createDescribedByProps, getNextCycleArrIdx, normalizeProps, isEmpty } from '../utils/common';
import { useLocale } from '../i18n/useLocale';
import { useFormField } from '../form/useFormField';
import { useFormField } from '../useFormField';
import { FieldTypePrefixes } from '../constants';
import { useErrorDisplay } from '../form/useErrorDisplay';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/useSearchField/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { createDescribedByProps, normalizeProps, propsToValues, useUniqId, withRefCapture } from '../utils/common';
import { useInputValidity } from '../validation/useInputValidity';
import { useLabel } from '../a11y/useLabel';
import { useFormField } from '../form/useFormField';
import { useFormField } from '../useFormField';
import { FieldTypePrefixes } from '../constants';
import { useErrorDisplay } from '../form/useErrorDisplay';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/useSlider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AriaLabelableProps, Arrayable, Direction, Orientation, Reactivify } fro
import { isNullOrUndefined, normalizeProps, useUniqId, withRefCapture } from '../utils/common';
import { toNearestMultipleOf } from '../utils/math';
import { useLocale } from '../i18n/useLocale';
import { useFormField } from '../form/useFormField';
import { useFormField } from '../useFormField';
import { FieldTypePrefixes } from '../constants';

export interface SliderProps {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/useSwitch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Ref, computed, shallowRef, toValue } from 'vue';
import { AriaDescribableProps, AriaLabelableProps, InputBaseAttributes, InputEvents, Reactivify } from '../types';
import { isEqual, normalizeProps, useUniqId, withRefCapture } from '../utils/common';
import { useLabel } from '../a11y/useLabel';
import { useFormField } from '../form/useFormField';
import { useFormField } from '../useFormField';
import { FieldTypePrefixes } from '../constants';

export interface SwitchDOMProps extends InputBaseAttributes, AriaLabelableProps, AriaDescribableProps, InputEvents {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/useTextField/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../types/common';
import { useInputValidity } from '../validation/useInputValidity';
import { useLabel } from '../a11y/useLabel';
import { useFormField } from '../form/useFormField';
import { useFormField } from '../useFormField';
import { FieldTypePrefixes } from '../constants';
import { useErrorDisplay } from '../form/useErrorDisplay';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/validation/useInputValidity.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nextTick, ref } from 'vue';
import { useInputValidity } from './useInputValidity';
import { fireEvent, render, screen } from '@testing-library/vue';
import { FormField, useFormField } from '../form';
import { FormField, useFormField } from '../useFormField';

test('updates the validity state on blur events', async () => {
const input = ref<HTMLInputElement>();
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/validation/useInputValidity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Ref, inject, nextTick, onMounted, shallowRef, watch } from 'vue';
import { useEventListener } from '../helpers/useEventListener';
import { FormField, FormKey } from '../form';
import { FormKey } from '../form';
import { Maybe } from '../types';
import { FormField } from '../useFormField';

interface InputValidityOptions {
inputRef?: Ref<HTMLInputElement | HTMLTextAreaElement | undefined>;
Expand Down

0 comments on commit 8f4697b

Please sign in to comment.