diff --git a/component-overview/examples/form/Checkbox-hiddenLabel.jsx b/component-overview/examples/form/Checkbox-hiddenLabel.jsx
index 3037c1debb..b61bb91fa3 100644
--- a/component-overview/examples/form/Checkbox-hiddenLabel.jsx
+++ b/component-overview/examples/form/Checkbox-hiddenLabel.jsx
@@ -2,7 +2,6 @@ import { Checkbox } from '@sb1/ffe-form-react';
+>Jeg har en ingen label
diff --git a/packages/ffe-form-react/src/Checkbox.js b/packages/ffe-form-react/src/Checkbox.js
index 3fbf35fd3d..2690775cee 100644
--- a/packages/ffe-form-react/src/Checkbox.js
+++ b/packages/ffe-form-react/src/Checkbox.js
@@ -1,44 +1,57 @@
-import React, { Fragment } from 'react';
+import React from 'react';
import { bool, node, string, func, oneOfType } from 'prop-types';
-import { v4 as hash } from 'uuid';
+import { v4 as uuid } from 'uuid';
import classNames from 'classnames';
-const Checkbox = React.forwardRef((props, ref) => {
- const { children, hiddenLabel, inline = true, noMargins, ...rest } = props;
+const Checkbox = React.forwardRef(
+ (
+ {
+ children,
+ hiddenLabel,
+ inline = true,
+ noMargins,
+ id = `checkbox-${uuid()}`,
+ ...rest
+ },
+ ref,
+ ) => {
+ const labelProps = {
+ className: classNames({
+ 'ffe-checkbox': true,
+ 'ffe-checkbox--inline': inline,
+ 'ffe-checkbox--no-margin': noMargins,
+ 'ffe-checkbox--hidden-label': hiddenLabel,
+ }),
+ htmlFor: id,
+ };
- const id = props.id || `checkbox-${hash()}`;
- const labelProps = {
- className: classNames({
- 'ffe-checkbox': true,
- 'ffe-checkbox--inline': inline,
- 'ffe-checkbox--no-margin': noMargins,
- 'ffe-checkbox--hidden-label': hiddenLabel,
- }),
- htmlFor: id,
- };
-
- return (
-
-
- {typeof children === 'function' ? (
- children(labelProps)
- ) : (
- // eslint-disable-next-line jsx-a11y/label-has-for
-
- )}
-
- );
-});
+ return (
+ <>
+
+ {typeof children === 'function' ? (
+ children(labelProps)
+ ) : (
+ // eslint-disable-next-line jsx-a11y/label-has-for
+
+ )}
+ >
+ );
+ },
+);
Checkbox.propTypes = {
/** Removes vertical margins from the checkbox */
@@ -49,7 +62,7 @@ Checkbox.propTypes = {
id: string,
inline: bool,
/** The label for the checkbox */
- children: oneOfType([node, func]),
+ children: oneOfType([node, func]).isRequired,
};
export default Checkbox;
diff --git a/packages/ffe-form-react/src/index.d.ts b/packages/ffe-form-react/src/index.d.ts
index a53d1efd11..1142d176b1 100644
--- a/packages/ffe-form-react/src/index.d.ts
+++ b/packages/ffe-form-react/src/index.d.ts
@@ -1,13 +1,13 @@
import * as React from 'react';
export interface CheckboxProps
- extends Omit, 'children'> {
+ extends Omit, 'children'> {
noMargins?: boolean;
hiddenLabel?: boolean;
id?: string;
inline?: boolean;
children?:
- | React.ReactNode
+ | NonNullable
| ((labelProps: {
className: string;
htmlFor: string;