PXD
v0.2.1-dev

useFormItem

Reads the enclosing PFormItem context inside a custom control, so the control can pick up its id, invalid state and ARIA wiring without props from the caller.

Exports

import { useFormItem } from 'pxd'

Types

import type { FormItemContext } from 'pxd'

Params

useFormItem() takes no arguments. It returns FormItemContext | null; null means the control is not inside a PFormItem.

<script setup lang="ts">
import { useFormItem } from 'pxd'

const item = useFormItem()
</script>

<template>
  <input
    :id="item?.id"
    :aria-invalid="item?.invalid || undefined"
    :aria-describedby="item?.describedBy || undefined"
    :aria-required="item?.required || undefined"
  />
</template>

Source

Source