@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
26 lines (25 loc) • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useFormFieldInput = void 0;
const common_1 = require("@workday/canvas-kit-react/common");
const useFormFieldModel_1 = require("./useFormFieldModel");
/**
* Adds the necessary props to an `Input` component.
* Used by the FormField.Input subcomponent and other input type components
*/
exports.useFormFieldInput = (0, common_1.createElemPropsHook)(useFormFieldModel_1.useFormFieldModel)(({ state }) => {
return {
required: state.isRequired ? true : undefined,
'aria-invalid': state.error === 'error' ? true : undefined,
'aria-describedby': state.id ? `hint-${state.id}` : undefined,
/**
* Provide an `aria-labelledby` for fields that need access to `label` directly
*/
'aria-labelledby': state.id ? `label-${state.id}` : undefined,
/**
* Provide an `id` to link the input via the `for` attribute on a `label`
*/
id: state.id ? `input-${state.id}` : undefined,
error: state.error,
};
});