Socket
Book a DemoInstallSign in
Socket

@slice-and-dice/govuk-react-error-summary

Package Overview
Dependencies
Maintainers
9
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@slice-and-dice/govuk-react-error-summary

Notice used to display form errors to user - also includes anchors to jump to relevant form sections.

latest
npmnpm
Version
0.7.3
Version published
Maintainers
9
Created
Source

ErrorSummary

Import

  import ErrorSummary from '@govuk-react/error-summary';

Usage

Simple

const heading = 'Message to alert the user to a problem goes here';
const description = 'Optional description of the errors and how to correct them';
const errors = [
  {
    targetName: 'national-insurance-number',
    text: 'National Insurance number error',
  },
  {
    targetName: 'description',
    text: 'Description of what you saw error',
  },
];

const onHandleErrorClick = (targetName) => {
  document.getElementsByName(targetName)[0].scrollIntoView();
};

<div>
  <ErrorSummary
    heading={heading}
    description={description}
    onHandleErrorClick={onHandleErrorClick}
    errors={errors}
  />
  <InputField
    name="national-insurance-number"
    hint="It’s on your National Insurance card, benefit letter, payslip or P60."
  >
    National Insurance number
  </InputField>
  <br />
  <TextArea name="description">Description of what you saw</TextArea>
</div>

References:

  • https://govuk-elements.herokuapp.com/errors/#summarise-errors
  • https://github.com/alphagov/govuk-frontend/tree/master/src/components/error-summary

TODO:

  • Swap out browser dependancy for context API to help with React Native support

Properties

PropRequiredDefaultTypeDescription
description``````stringOptional description of the errors
errors``````arrayOf[object Object]Array of errors with text and target element name to scroll into view when clicked
heading'There is a problem'stringHeading text
onHandleErrorClick``````funconClick function to scroll the target element into view

FAQs

Package last updated on 11 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts