Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💄 Oppdatert label/description for skjemakomponenter #1967

Merged
merged 3 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/cyan-cars-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@navikt/ds-css": patch
"@navikt/ds-react": patch
---

:lipstick: Oppdatert Label og Description spacing for skjemakomponenter
2 changes: 1 addition & 1 deletion @navikt/core/css/form/fieldset.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}

.navds-fieldset > .navds-fieldset__description:not(:empty) {
margin-top: var(--a-spacing-1);
margin-top: 0.125rem;
}

/* Applied when hideLegend is applied to fieldset */
Expand Down
6 changes: 5 additions & 1 deletion @navikt/core/css/form/form.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}

.navds-form-field__description {
margin-top: -4px;
margin-top: -6px;
}

.navds-form-field .navds-error-message,
Expand All @@ -27,3 +27,7 @@
.navds-form-field__error:empty {
display: none;
}

.navds-form-field__subdescription {
color: var(--ac-form-subdescription, var(--a-text-subtle));
}
2 changes: 1 addition & 1 deletion @navikt/core/css/form/radio-checkbox.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
.navds-radio__content {
display: flex;
flex-direction: column;
gap: var(--a-spacing-1);
gap: 0.125rem;
}

.navds-checkbox--small > .navds-checkbox__input,
Expand Down
2 changes: 1 addition & 1 deletion @navikt/core/css/form/switch.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
.navds-switch__content {
display: flex;
flex-direction: column;
gap: var(--a-spacing-1);
gap: 0.125rem;
padding: 0.75rem 0 0.75rem 3.25rem;
}

Expand Down
38 changes: 13 additions & 25 deletions @navikt/core/react/src/form/Fieldset/Fieldset.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cl from "clsx";
import React, { FieldsetHTMLAttributes, forwardRef, useContext } from "react";
import { BodyLong, Detail, Label, ErrorMessage, omit } from "../..";
import { BodyShort, ErrorMessage, Label, omit } from "../..";
import { FormFieldProps } from "../useFormField";
import { useFieldset } from "./useFieldset";

Expand Down Expand Up @@ -104,30 +104,18 @@ export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
>
{legend}
</Label>
{!!description &&
(size === "medium" ? (
<BodyLong
className={cl("navds-fieldset__description", {
"navds-sr-only": !!hideLegend,
})}
id={inputDescriptionId}
size="small"
as="div"
>
{props.description}
</BodyLong>
) : (
<Detail
className={cl("navds-fieldset__description", {
"navds-sr-only": !!hideLegend,
})}
id={inputDescriptionId}
size="small"
as="div"
>
{props.description}
</Detail>
))}
{!!description && (
<BodyShort
className={cl("navds-fieldset__description", {
"navds-sr-only": !!hideLegend,
})}
id={inputDescriptionId}
size={size ?? "medium"}
as="div"
>
{props.description}
</BodyShort>
)}
{children}
<div
id={errorId}
Expand Down
39 changes: 12 additions & 27 deletions @navikt/core/react/src/form/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { forwardRef, SelectHTMLAttributes } from "react";
import cl from "clsx";
import React, { forwardRef, SelectHTMLAttributes } from "react";

import { ChevronDownIcon } from "@navikt/aksel-icons";
import { BodyLong, Label, ErrorMessage, omit, Detail } from "..";
import { BodyShort, ErrorMessage, Label, omit } from "..";
import { FormFieldProps, useFormField } from "./useFormField";

export interface SelectProps
Expand Down Expand Up @@ -74,31 +74,16 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
{label}
</Label>
{!!description && (
<>
{size === "medium" ? (
<BodyLong
className={cl("navds-form-field__description", {
"navds-sr-only": hideLabel,
})}
id={inputDescriptionId}
size="small"
as="div"
>
{description}
</BodyLong>
) : (
<Detail
className={cl("navds-form-field__description", {
"navds-sr-only": hideLabel,
})}
id={inputDescriptionId}
size="small"
as="div"
>
{description}
</Detail>
)}
</>
<BodyShort
className={cl("navds-form-field__description", {
"navds-sr-only": hideLabel,
})}
id={inputDescriptionId}
size={size}
as="div"
>
{description}
</BodyShort>
)}
<div className="navds-select__container" style={style}>
<select
Expand Down
12 changes: 5 additions & 7 deletions @navikt/core/react/src/form/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, {
useEffect,
useState,
} from "react";
import { BodyShort, Detail, Loader, omit } from "..";
import { BodyShort, Loader, omit } from "..";
import { FormFieldProps, useFormField } from "./useFormField";

const SelectedIcon = () => (
Expand Down Expand Up @@ -71,8 +71,6 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
...rest
} = props;

const Description = size === "medium" ? BodyShort : Detail;

const [checked, setChecked] = useState(
defaultChecked ?? checkedProp ?? false
);
Expand Down Expand Up @@ -130,13 +128,13 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
{children}
</BodyShort>
{description && (
<Description
<BodyShort
size={size}
as="div"
size="small"
className="navds-switch__description"
className="navds-form-field__subdescription navds-switch__description"
>
{description}
</Description>
</BodyShort>
)}
</div>
</label>
Expand Down
39 changes: 12 additions & 27 deletions @navikt/core/react/src/form/TextField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { forwardRef, InputHTMLAttributes } from "react";
import cl from "clsx";
import { BodyLong, Detail, Label, ErrorMessage, omit } from "..";
import React, { forwardRef, InputHTMLAttributes } from "react";
import { BodyShort, ErrorMessage, Label, omit } from "..";
import { FormFieldProps, useFormField } from "./useFormField";

export interface TextFieldProps
Expand Down Expand Up @@ -78,31 +78,16 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
</Label>

{!!description && (
<>
{size === "medium" ? (
<BodyLong
className={cl("navds-form-field__description", {
"navds-sr-only": hideLabel,
})}
id={inputDescriptionId}
size="small"
as="div"
>
{description}
</BodyLong>
) : (
<Detail
className={cl("navds-form-field__description", {
"navds-sr-only": hideLabel,
})}
id={inputDescriptionId}
size="small"
as="div"
>
{description}
</Detail>
)}
</>
<BodyShort
className={cl("navds-form-field__description", {
"navds-sr-only": hideLabel,
})}
id={inputDescriptionId}
size={size}
as="div"
>
{description}
</BodyShort>
)}
<input
{...omit(rest, ["error", "errorId", "size"])}
Expand Down
42 changes: 13 additions & 29 deletions @navikt/core/react/src/form/Textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { forwardRef, useState } from "react";
import cl from "clsx";
import { BodyShort, BodyLong, Label, ErrorMessage, omit, Detail } from "..";
import { FormFieldProps, useFormField } from "./useFormField";
import { useId } from "..";
import React, { forwardRef, useState } from "react";
import { BodyShort, ErrorMessage, Label, omit, useId } from "..";
import TextareaAutosize from "../util/TextareaAutoSize";
import { FormFieldProps, useFormField } from "./useFormField";

/**
* TODO: Mulighet for lokalisering av sr-only/counter text
Expand Down Expand Up @@ -120,31 +119,16 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
{label}
</Label>
{!!description && (
<>
{size === "medium" ? (
<BodyLong
className={cl("navds-form-field__description", {
"navds-sr-only": hideLabel,
})}
id={inputDescriptionId}
size="small"
as="div"
>
{description}
</BodyLong>
) : (
<Detail
className={cl("navds-form-field__description", {
"navds-sr-only": hideLabel,
})}
id={inputDescriptionId}
size="small"
as="div"
>
{description}
</Detail>
)}
</>
<BodyShort
className={cl("navds-form-field__description", {
"navds-sr-only": hideLabel,
})}
id={inputDescriptionId}
size={size}
as="div"
>
{description}
</BodyShort>
)}
<div className="navds-textarea__wrapper">
<TextareaAutosize
Expand Down
12 changes: 7 additions & 5 deletions @navikt/core/react/src/form/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cl from "clsx";
import React, { forwardRef, InputHTMLAttributes } from "react";
import { BodyLong, BodyShort, Detail } from "../../typography";
import { BodyShort } from "../../typography";
import { omit } from "../../util";
import { FormFieldProps } from "../useFormField";
import useCheckbox from "./useCheckbox";
Expand Down Expand Up @@ -44,8 +44,6 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
(props, ref) => {
const { inputProps, hasError, size } = useCheckbox(props);

const Description = size === "medium" ? BodyLong : Detail;

return (
<div
className={cl(
Expand Down Expand Up @@ -94,9 +92,13 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
{props.children}
</BodyShort>
{props.description && (
<Description as="span" className="navds-checkbox__description">
<BodyShort
as="span"
size={size}
className="navds-form-field__subdescription navds-checkbox__description"
>
{props.description}
</Description>
</BodyShort>
)}
</span>
</label>
Expand Down
12 changes: 7 additions & 5 deletions @navikt/core/react/src/form/radio/Radio.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cl from "clsx";
import React, { forwardRef, InputHTMLAttributes } from "react";
import { BodyLong, BodyShort, Detail } from "../../typography";
import { BodyShort } from "../../typography";
import { omit } from "../../util";
import { FormFieldProps } from "../useFormField";
import { useRadio } from "./useRadio";
Expand All @@ -25,8 +25,6 @@ export interface RadioProps
export const Radio = forwardRef<HTMLInputElement, RadioProps>((props, ref) => {
const { inputProps, size, hasError } = useRadio(props);

const Description = size === "medium" ? BodyLong : Detail;

return (
<div
className={cl(props.className, "navds-radio", `navds-radio--${size}`, {
Expand All @@ -46,9 +44,13 @@ export const Radio = forwardRef<HTMLInputElement, RadioProps>((props, ref) => {
{props.children}
</BodyShort>
{props.description && (
<Description as="span" className="navds-radio__description">
<BodyShort
as="span"
size={size}
className="navds-form-field__subdescription navds-radio__description"
>
{props.description}
</Description>
</BodyShort>
)}
</span>
</label>
Expand Down
4 changes: 3 additions & 1 deletion @navikt/core/react/src/form/radio/radio.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export const GroupDescription = () => (
defaultValue="tekst2"
description="Group description"
>
<Radio value="tekst">Radiotekst</Radio>
<Radio value="tekst" description="textdesc">
Radiotekst
</Radio>
<Radio value="tekst2">Radiotekst</Radio>
</RadioGroup>
);
2 changes: 1 addition & 1 deletion @navikt/core/react/src/form/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
</Label>
{!!description && (
<BodyShort
as="div"
className={cl("navds-form-field__description", {
"navds-sr-only": hideLabel,
})}
id={inputDescriptionId}
size={size}
as="div"
>
{description}
</BodyShort>
Expand Down