-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose internal inputs (#2439)
Relates to #2308 Expose input elements of form elements, so that the native functions like `focus` or `select` can be used.
- Loading branch information
Showing
14 changed files
with
165 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"sit-onyx": minor | ||
--- | ||
|
||
feat: Expose input elements of form elements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/sit-onyx/src/components/OnyxForm/FormElementTestWrapper.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script setup lang="ts"> | ||
import { useTemplateRef, type Component } from "vue"; | ||
const props = defineProps<{ | ||
/** | ||
* Name of the component | ||
*/ | ||
name: string; | ||
/** | ||
* Which component to wrap | ||
*/ | ||
is: Component; | ||
}>(); | ||
const formElement = useTemplateRef<{ input: { focus: () => void } }>("fromElement"); | ||
</script> | ||
|
||
<template> | ||
<!-- eslint-disable-next-line sitOnyx/require-root-class --> | ||
<button type="button" @click="formElement?.input.focus()"> | ||
form-element-test-wrapper-focus-button-{{ props.name }} | ||
</button> | ||
<component | ||
:is="props.is" | ||
ref="formElement" | ||
:label="`form-element-test-wrapper-label-${props.name}`" | ||
:options="[]" | ||
/> | ||
</template> |
42 changes: 42 additions & 0 deletions
42
packages/sit-onyx/src/components/OnyxForm/OnyxForm.core.spec-d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,49 @@ | ||
import { expectTypeOf, it } from "vitest"; | ||
import type { ComponentExposed, ComponentProps } from "vue-component-type-helpers"; | ||
import type { CustomMessageType } from "../../composables/useCustomValidity"; | ||
import type OnyxCheckbox from "../OnyxCheckbox/OnyxCheckbox.vue"; | ||
import type OnyxCheckboxGroup from "../OnyxCheckboxGroup/OnyxCheckboxGroup.vue"; | ||
import type OnyxInput from "../OnyxInput/OnyxInput.vue"; | ||
import type OnyxRadioButton from "../OnyxRadioButton/OnyxRadioButton.vue"; | ||
import type OnyxRadioGroup from "../OnyxRadioGroup/OnyxRadioGroup.vue"; | ||
import type OnyxSelect from "../OnyxSelect/OnyxSelect.vue"; | ||
import type OnyxStepper from "../OnyxStepper/OnyxStepper.vue"; | ||
import OnyxSwitch from "../OnyxSwitch/OnyxSwitch.vue"; | ||
import type OnyxTextarea from "../OnyxTextarea/OnyxTextarea.vue"; | ||
import { type __DONT_USE_VUE_FIX_KeyOfFormProps, type FormProps } from "./OnyxForm.core"; | ||
|
||
it("should be ensured that _KeyofFormProps includes all keys of FormProps", async () => { | ||
expectTypeOf<keyof FormProps>().toMatchTypeOf<__DONT_USE_VUE_FIX_KeyOfFormProps>(); | ||
expectTypeOf<__DONT_USE_VUE_FIX_KeyOfFormProps>().toMatchTypeOf<keyof FormProps>(); | ||
}); | ||
|
||
type AllOnyxFormElements = | ||
| typeof OnyxSelect | ||
| typeof OnyxInput | ||
| typeof OnyxTextarea | ||
| typeof OnyxRadioButton | ||
| typeof OnyxCheckbox | ||
| typeof OnyxStepper | ||
| typeof OnyxSwitch; | ||
|
||
it("should be ensured that all onyx form elements support the basic input props", async () => { | ||
expectTypeOf<ComponentProps<AllOnyxFormElements>>().toMatchTypeOf<{ | ||
modelValue?: unknown; | ||
label: string; | ||
customError?: CustomMessageType; | ||
}>(); | ||
}); | ||
|
||
it("should be ensured that all onyx form elements expose the internal input", async () => { | ||
expectTypeOf<ComponentExposed<AllOnyxFormElements>>().toMatchTypeOf<{ | ||
input: (HTMLInputElement | HTMLTextAreaElement) | null | undefined; | ||
}>(); | ||
}); | ||
|
||
type AllOnyxFormGroups = typeof OnyxCheckboxGroup | typeof OnyxRadioGroup; | ||
|
||
it("should be ensured that all onyx form element groups expose the internal inputs", async () => { | ||
expectTypeOf<ComponentExposed<AllOnyxFormGroups>>().toMatchTypeOf<{ | ||
inputs: HTMLInputElement[]; | ||
}>(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.