Skip to Content
Piplup
@piplup/rhf-adaptershtmlComponents

HtmlButtonElement

HtmlButtonElement wires native submit, reset and plain buttons to react-hook-form form state, without extra plumbing.

HtmlButtonElement is a native <button> wrapper for React Hook Form-aware actions such as submit, reset, and state-driven button disabling.

Import

import { HtmlButtonElement } from '@piplup/rhf-adapters/html';

Usage

Submit

'use client';import { HtmlButtonElement, HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() {  const { control, handleSubmit } = useForm({    defaultValues: {      input: '',    },  });  return (    <form      onSubmit={handleSubmit((data) => {        alert(JSON.stringify(data, null, 2));      })}      noValidate    >      <div>        <HtmlInputElement          className="border px-2 block rounded"          control={control}          name="input"          placeholder="Type text here"          type="text"          disableOnIsSubmitting        />      </div>      <div>        <HtmlButtonElement          className="bg-black hover:bg-black/90 px-4 py-1 text-white rounded mt-3"          control={control}          type="submit"          disableOnIsSubmitting        >          Submit        </HtmlButtonElement>      </div>    </form>  );}

Reset

'use client';import { HtmlButtonElement, HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() {  const { control, handleSubmit } = useForm({    defaultValues: {      input: '',    },  });  return (    <form      onSubmit={handleSubmit((data) => {        alert(JSON.stringify(data, null, 2));      })}      noValidate    >      <div>        <HtmlInputElement          className="border px-2 block rounded"          control={control}          name="input"          placeholder="Type text here"          type="text"        />      </div>      <div>        <HtmlButtonElement          className="bg-black hover:bg-black/90 px-4 py-1 text-white rounded mt-3"          control={control}          type="reset"        >          Reset        </HtmlButtonElement>      </div>    </form>  );}

Button

'use client';import { HtmlButtonElement, HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() {  const { control, handleSubmit } = useForm({    defaultValues: {      input: '',    },  });  return (    <form      onSubmit={handleSubmit((data) => {        alert(JSON.stringify(data, null, 2));      })}      noValidate    >      <div>        <HtmlInputElement          className="border px-2 block rounded"          control={control}          name="input"          placeholder="Type text here"          type="text"        />      </div>      <div>        <HtmlButtonElement          className="bg-black hover:bg-black/90 px-4 py-1 text-white rounded mt-3"          control={control}          type="button"        >          Button        </HtmlButtonElement>      </div>    </form>  );}

Props

Prop

Type

HtmlButtonElement accepts standard native button attributes alongside adapter props such as control, disableOnError, and disableOnIsSubmitting.

The ref is forwarded to the underlying <button> element.

useHtmlButtonAdapter

useHtmlButtonAdapter returns normalized button props for building custom button components that respond to React Hook Form state such as submit state, errors, and disabled behavior.

Import

import { useHtmlButtonAdapter } from '@piplup/rhf-adapters/html';
import * as React from 'react';import { useHtmlButtonAdapter } from './adapter';import type { UseHtmlButtonAdapterProps } from './adapter';import type { FieldValues } from 'react-hook-form';export interface HtmlButtonElementProps<TFieldValues extends FieldValues = FieldValues>  extends    Omit<React.ComponentProps<'button'>, 'name' | 'style'>,    Omit<      UseHtmlButtonAdapterProps<TFieldValues>,      'composeClassName' | 'composeHelperText' | 'helperText' | 'internalClasses' | 'onClick'    > {}function HtmlButtonComponent<TFieldValues extends FieldValues = FieldValues>(  props: HtmlButtonElementProps<TFieldValues>,  ref?: React.Ref<HTMLButtonElement>,): React.ReactElement {  const {    classes,    className,    control,    disabled,    disableOnError,    disableOnIsSubmitting,    error,    errorParser,    exact,    name,    onClick,    style,    type,    ...rest  } = props;  const {    error: _error,    helperText: _helperText,    ...adapter  } = useHtmlButtonAdapter<TFieldValues, HTMLButtonElement>(    {      classes,      className,      composeClassName: true,      composeHelperText: false,      control,      disabled,      disableOnError,      disableOnIsSubmitting,      error,      errorParser,      exact,      helperText: undefined,      name,      onClick,      style,      type,    },    ref,  );  // eslint-disable-next-line react/button-has-type -- the type comes from the props  return <button {...rest} {...adapter} />;}export const HtmlButtonElement = React.forwardRef(  HtmlButtonComponent,) as typeof HtmlButtonComponent & { displayName?: string };if (process.env.NODE_ENV !== 'production') {  HtmlButtonElement.displayName = 'HtmlButtonElement';}

Props

Prop

Type

Return value

Prop

Type

Notes

  • The hook is built on top of useFormStateAdapter.
  • type="submit" and type="reset" preserve native form semantics while still allowing adapter-managed disabling.

Notes

  • Use type="submit" or type="reset" to delegate to the surrounding form.
  • Use disableOnError or disableOnIsSubmitting when the button should react to form state automatically.

See also

On this page