Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

### Added

- **Field**: Add `data-required` attribute to Field.Label part

## [5.22.0] - 2025-08-28

### Added
Expand Down
12 changes: 12 additions & 0 deletions packages/react/src/components/field/examples/custom-control.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Field } from '@ark-ui/react/field'

export const CustomControl = () => {
return (
<Field.Root invalid>
<Field.Label>Any Control</Field.Label>
<Field.Context>{(field) => <input {...field.getInputProps()} />}</Field.Context>
<Field.HelperText>Uses getControlProps() for maximum flexibility</Field.HelperText>
<Field.ErrorText>This field has an error</Field.ErrorText>
</Field.Root>
)
}
3 changes: 2 additions & 1 deletion packages/react/src/components/field/field.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const meta: Meta = {

export default meta

export { Disabled } from './examples/disabled'
export { Input } from './examples/input'
export { Invalid } from './examples/invalid'
export { RequiredIndicator } from './examples/required-indicator'
Expand All @@ -15,3 +14,5 @@ export { Select } from './examples/select'
export { ShadowDom } from './examples/shadow-dom'
export { Textarea } from './examples/textarea'
export { TextareaAutoresize } from './examples/textarea-autoresize'
export { Disabled } from './examples/disabled'
export { CustomControl } from './examples/custom-control'
3 changes: 2 additions & 1 deletion packages/react/src/components/field/use-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ export const useField = (props: UseFieldProps = {}) => {
'data-disabled': dataAttr(disabled),
'data-invalid': dataAttr(invalid),
'data-readonly': dataAttr(readOnly),
'data-required': dataAttr(required),
htmlFor: id,
}) as HTMLProps<'label'>,
[disabled, invalid, readOnly, id, labelId],
[disabled, invalid, readOnly, required, id, labelId],
)

const getControlProps = useMemo(
Expand Down
4 changes: 4 additions & 0 deletions packages/solid/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

### Added

- **Field**: Add `data-required` attribute to Field.Label part

## [5.22.0] - 2025-08-28

### Added
Expand Down
12 changes: 12 additions & 0 deletions packages/solid/src/components/field/examples/custom-control.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Field } from '@ark-ui/solid/field'

export const CustomControl = () => {
return (
<Field.Root invalid>
<Field.Label>Any Control</Field.Label>
<Field.Context>{(field) => <input {...field().getInputProps()} />}</Field.Context>
<Field.HelperText>Uses getControlProps() for maximum flexibility</Field.HelperText>
<Field.ErrorText>This field has an error</Field.ErrorText>
</Field.Root>
)
}
1 change: 1 addition & 0 deletions packages/solid/src/components/field/field.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export { Select } from './examples/select'
export { Textarea } from './examples/textarea'
export { TextareaAutoresize } from './examples/textarea-autoresize'
export { Disabled } from './examples/disabled'
export { CustomControl } from './examples/custom-control'
1 change: 1 addition & 0 deletions packages/solid/src/components/field/use-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const useField = (props?: MaybeAccessor<UseFieldProps>) => {
'data-disabled': dataAttr(fieldProps.disabled),
'data-invalid': dataAttr(fieldProps.invalid),
'data-readonly': dataAttr(fieldProps.readOnly),
'data-required': dataAttr(fieldProps.required),
htmlFor: id,
})

Expand Down
4 changes: 4 additions & 0 deletions packages/svelte/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ description: All notable changes will be documented in this file.

## [Unreleased]

### Added

- **Field**: Add `data-required` attribute to Field.Label part

## [5.7.0] - 2025-08-28

### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script lang="ts">
import { Field } from '@ark-ui/svelte/field'
</script>

<Field.Root invalid>
<Field.Label>Any Control</Field.Label>
<Field.Context>
{#snippet render(field)}
<input {...field().getInputProps()} />
{/snippet}
</Field.Context>
<Field.HelperText>Uses getControlProps() for maximum flexibility</Field.HelperText>
<Field.ErrorText>This field has an error</Field.ErrorText>
</Field.Root>
7 changes: 7 additions & 0 deletions packages/svelte/src/lib/components/field/field.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import RootProviderExample from './examples/root-provider.svelte'
import SelectExample from './examples/select.svelte'
import TextareaAutoresizeExample from './examples/textarea-autoresize.svelte'
import TextareaExample from './examples/textarea.svelte'
import CustomControlExample from './examples/custom-control.svelte'

const meta: Meta = {
title: 'Components/Field',
Expand Down Expand Up @@ -57,6 +58,12 @@ export const Disabled = {
}),
}

export const CustomControl = {
render: () => ({
Component: CustomControlExample,
}),
}

export const RootProvider = {
render: () => ({
Component: RootProviderExample,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const useField = (inProps: MaybeFunction<UseFieldProps> = {}) => {
'data-disabled': dataAttr(disabled),
'data-invalid': dataAttr(invalid),
'data-readonly': dataAttr(readOnly),
'data-required': dataAttr(required),
for: controlId,
}) as HTMLProps<'label'>

Expand Down
4 changes: 4 additions & 0 deletions packages/vue/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

### Added

- **Field**: Add `data-required` attribute to Field.Label part

## [5.22.0] - 2025-08-28

### Added
Expand Down
14 changes: 14 additions & 0 deletions packages/vue/src/components/field/examples/custom-control.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script setup lang="ts">
import { Field } from '@ark-ui/vue/field'
</script>

<template>
<Field.Root invalid>
<Field.Label>Any Control</Field.Label>
<Field.Context v-slot="field">
<input v-bind="field.getInputProps()" />
</Field.Context>
<Field.HelperText>Uses getControlProps() for maximum flexibility</Field.HelperText>
<Field.ErrorText>This field has an error</Field.ErrorText>
</Field.Root>
</template>
4 changes: 4 additions & 0 deletions packages/vue/src/components/field/field.stories.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Select from './examples/select.vue'
import TextareaAutoresize from './examples/textarea-autoresize.vue'
import TextareaControlled from './examples/textarea-controlled.vue'
import Textarea from './examples/textarea.vue'
import CustomControl from './examples/custom-control.vue'
</script>
<template>
<Story title="Field">
Expand All @@ -28,6 +29,9 @@ import Textarea from './examples/textarea.vue'
<Variant title="Disabled">
<Disabled />
</Variant>
<Variant title="Custom Control">
<CustomControl />
</Variant>
<Variant title="Textarea">
<Textarea />
</Variant>
Expand Down
1 change: 1 addition & 0 deletions packages/vue/src/components/field/use-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const useField = (props: MaybeRef<UseFieldProps> = {}) => {
'data-disabled': dataAttr(values.disabled),
'data-invalid': dataAttr(values.invalid),
'data-readonly': dataAttr(values.readOnly),
'data-required': dataAttr(values.required),
htmlFor: id.value,
}
}
Expand Down
7 changes: 7 additions & 0 deletions website/src/content/pages/components/field.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ have maximum control over the field programmatically.

> If you're using the `Field.RootProvider` component, you don't need to use the `Field.Root` component.

### Custom Control

Use the `Field.Context` or `useFieldContext` hook to access the internal state of the field.This can help you wire up
custom controls with the `Field` component.

<Example id="custom-control" />

## API Reference

<ComponentTypes id="field" />