Skip to content

Commit 85f9c60

Browse files
Merge pull request #2129 from navikt/flagg-for-expandall
Tillater å sette et flagg i URL for å åpne alle ekspanderbare elementer
2 parents 51e2f91 + f86e07f commit 85f9c60

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/components/_common/accordion/Accordion.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export const Accordion = ({ accordion }: AccordionProps) => {
4848
};
4949

5050
useEffect(() => {
51+
if (window.location.toString().includes('expandall=true')) {
52+
expandAll();
53+
return;
54+
}
5155
const anchorHash = window.location.hash || '';
5256
const matchingAccordion = accordion.findIndex(
5357
(item) => validatePanel(item) && item.anchorId === anchorHash.slice(1)

src/components/_common/expandable/Expandable.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ export const Expandable = ({
6363
return;
6464
}
6565

66+
if (window.location.toString().includes('expandall=true')) {
67+
setIsOpen(true);
68+
return;
69+
}
70+
6671
const targetId = window.location.hash.replace('#', '');
6772
if (!targetId) {
6873
return;

src/components/parts/readMorePart/ReadMorePart.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef, useState } from 'react';
1+
import React, { useEffect, useRef, useState } from 'react';
22
import { ReadMore } from '@navikt/ds-react';
33
import { EditorHelp } from 'components/_editor-only/editor-help/EditorHelp';
44
import { ParsedHtml } from 'components/_common/parsedHtml/ParsedHtml';
@@ -32,6 +32,12 @@ export const ReadMorePart = ({ config }: PartComponentProps<PartType.ReadMore>)
3232
callback: () => setIsOpen(true),
3333
});
3434

35+
useEffect(() => {
36+
if (window.location.toString().includes('expandall=true')) {
37+
setIsOpen(true);
38+
}
39+
}, []);
40+
3541
if (!config?.html || !config.title) {
3642
return <EditorHelp text={'Legg inn tittel og beskrivelse for "les mer".'} type={'error'} />;
3743
}

0 commit comments

Comments
 (0)