npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

oaf-react-final-form

v0.53.0

Published

[![Build Status](https://github.com/oaf-project/oaf-react-final-form/actions/workflows/main.yml/badge.svg)](https://github.com/oaf-project/oaf-react-final-form/actions/workflows/main.yml) [![type-coverage](https://img.shields.io/badge/dynamic/json.svg?lab

Downloads

18

Readme

Oaf React Final Form

Build Status type-coverage Codecov Mutation testing badge

Known Vulnerabilities npm

An opinionated form library.

  • TypeScript + React Final Form
  • Strict type safety
  • Validation built with io-ts
  • Accessible by default
    • By default we render accessible form labels and validation feedback (with aria-invalid and aria-labelledby)
    • We follow the guidance from https://www.tpgi.com/required-attribute-requirements/
      • We use the novalidate attribute on the form element to disable browsers’ client-side validation. Instead, we implement custom validation and accessible error messaging.
      • To ensure most screen readers won’t default to announcing required form controls as invalid, we use aria-invalid="false". We update this to true if the current value (or lack thereof) of a required control does not pass validation.
      • We use aria-describedby on required form controls to point to the element that contains the inline error message.
      • We wait until the control has lost focus before marking a form control as invalid and displaying the inline error message. We do this by defaulting React Final Form's validateOnBlur option to true. See https://github.com/final-form/final-form/issues/250. As a consequence, we include work-arounds for https://github.com/final-form/final-form/issues/213 and https://github.com/final-form/react-final-form/issues/458
    • After a failed form submission, we move focus to the first invalid form element (using https://github.com/oaf-project/oaf-side-effects)
    • We follow the advice from https://webaim.org/techniques/formvalidation/

Installation

# yarn
yarn add oaf-react-final-form

# npm
npm install oaf-react-final-form

Usage

  // First, we define the form codec using io-ts.
  // See https://github.com/gcanti/io-ts#the-idea
  //
  // `formCodec` is just a convenience function over the top of
  // `intersection`, `type`, `partial` and `readonly` from io-ts.
  // See https://github.com/gcanti/io-ts#mixing-required-and-optional-props
  const codec = formCodec({
    optional: {
      foo: t.string,
    },
  });

  // We derive React components for our form elements from the form codec. This
  // gives us some type-safety benefits when rendering these form elements (below).
  const { Form, Input, Select } = elementsForCodec(codec);

  type FormData = t.TypeOf<typeof codec>;

  const onSubmit = (formData: FormData): SubmissionResponse<FormData> => {
    // Here we are guaranteed that `formData` has been parsed by our form codec.
    // We can return submission errors here if necessary.
    return undefined;
  };

  const form = (
    <Form onSubmit={onSubmit}>
      {/*
        The `name` attr must be one of the values from the form codec.
        The `type` and `required` attrs must be compatible with the corresponding property from the form codec.
          * Because `foo` is optional in the codec, `required` must be either undefined or false.
          * Because `foo` is a string in the codec, `type` cannot be one of the numeric input types (`number` or `range`).
      */}
      <Input label="foo" name="foo" type="text" />
    </Form>
  );

See Form.test.tsx for more examples.