UNPKG

@amsterdam/design-system-react

Version:

All React components from the Amsterdam Design System. Use it to compose pages in your website or application.

20 lines (19 loc) 1.19 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { forwardRef, useState } from 'react'; import { InvalidFormAlertWithErrors } from './InvalidFormAlertWithErrors'; import { useAddErrorCountToDocumentTitle } from './useAddErrorCountToDocumentTitle'; /** * @see {@link https://designsystem.amsterdam/?path=/docs/components-forms-invalid-form-alert--docs Invalid Form Alert docs at Amsterdam Design System} */ export const InvalidFormAlert = forwardRef(({ errorCountLabel, errors, ...restProps }, ref) => { // An Invalid Form Alert without errors only resets the document title. // With errors, it renders the InvalidFormAlertWithErrors component. useAddErrorCountToDocumentTitle(errors, errorCountLabel); // Focus should only be set on first render of InvalidFormAlertWithErrors. // Subsequent renders should not set focus. const [hasFocusedOnce, setHasFocusedOnce] = useState(false); if (errors.length === 0) return undefined; return (_jsx(InvalidFormAlertWithErrors, { ...restProps, errors: errors, hasFocusedOnce: hasFocusedOnce, ref: ref, setHasFocusedOnce: setHasFocusedOnce })); }); InvalidFormAlert.displayName = 'InvalidFormAlert';