Skip to content

Commit f27bf8b

Browse files
Merge pull request #1946 from navikt/klikkbar-h3-lenke
Gjør h3 anker klikkbare og flytter offset til Header
2 parents 268fce2 + 783ded4 commit f27bf8b

File tree

6 files changed

+11
-31
lines changed

6 files changed

+11
-31
lines changed

src/components/_common/headers/Header.module.scss

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
}
1313
}
1414

15-
.anchor {
15+
.anchorOffset {
16+
position: relative;
17+
transform: translateY(calc(var(--a-spacing-20) * -1));
18+
}
19+
20+
.anchorLink {
1621
font-size: inherit;
1722
color: inherit;
1823
text-decoration: inherit;

src/components/_common/headers/Header.tsx

+5-16
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,19 @@ type Props = {
1111
level: Level;
1212
size?: Size;
1313
anchorId?: string;
14-
addAnchorId?: boolean;
1514
className?: string;
1615
};
1716

18-
export const Header = ({
19-
children,
20-
size,
21-
level,
22-
anchorId,
23-
className,
24-
addAnchorId = true, // Can be set to false if anchor is added outside of Header
25-
}: Props) => {
17+
export const Header = ({ children, size, level, anchorId, className }: Props) => {
2618
const anchor = anchorId ? (anchorId.startsWith('#') ? anchorId : `#${anchorId}`) : undefined;
2719
const fallbackSizeByLevel = levelToSize[level] || 'large';
2820

2921
return (
30-
<div
31-
className={classNames(style.header, className)}
32-
id={addAnchorId ? anchorId : undefined}
33-
tabIndex={-1}
34-
>
22+
<div className={classNames(style.header, className)}>
23+
<div className={style.anchorOffset} id={anchorId} tabIndex={-1} />
3524
<Heading size={size || fallbackSizeByLevel} level={level}>
36-
{anchor && level === '2' ? (
37-
<a href={anchor} className={style.anchor}>
25+
{anchor && (level === '2' || level === '3') ? (
26+
<a href={anchor} className={style.anchorLink}>
3827
{children}
3928
</a>
4029
) : (

src/components/layouts/flex-cols/FlexColsLayout.module.scss

-5
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@
135135
}
136136
}
137137

138-
.anchorOffset {
139-
position: relative;
140-
transform: translateY(calc(var(--a-spacing-20) * -1));
141-
}
142-
143138
.shelfHeader:before {
144139
@include common.header-before-rectangle();
145140
}

src/components/layouts/flex-cols/SituationPageFlexColsLayout.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@ export const SituationPageFlexColsLayout = ({ pageProps, layoutProps }: Props) =
5050
layoutProps={layoutProps}
5151
>
5252
<div className={style.contentWrapper}>
53-
<div className={style.anchorOffset} id={anchorId} />
5453
{title && (
5554
<Header
5655
level="2"
5756
size="large"
5857
anchorId={anchorId}
59-
addAnchorId={false}
6058
className={classNames(style.header, isShelf && style.shelfHeader)}
6159
>
6260
{title}

src/components/layouts/section-with-header/SectionWithHeaderLayout.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,11 @@ export const SectionWithHeaderLayout = ({ pageProps, layoutProps }: Props) => {
9797
/>
9898
</div>
9999
)}
100-
<div className={style.anchorOffset} id={anchorId} />
101100
{title && (
102101
<Header
103102
size="large"
104103
level="2"
105104
anchorId={anchorId}
106-
addAnchorId={false}
107105
className={classNames(style.header, !!iconImgProps && style.headerWithIcon)}
108106
>
109107
{title}

src/components/layouts/section-with-header/SectionWithHeaderLayoutV2.module.scss

-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ $defaultBgColor: white;
4242
@include common.header-before-rectangle();
4343
}
4444

45-
.anchorOffset {
46-
position: relative;
47-
transform: translateY(calc(var(--a-spacing-20) * -1));
48-
}
49-
5045
.header {
5146
margin-bottom: var(--a-spacing-4);
5247
color: var(--brand-purple-deep);

0 commit comments

Comments
 (0)