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

🐛 Modal: Hindre at elementer med sr-only posisjoneres feil #2541

Merged
merged 1 commit into from
Dec 5, 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
5 changes: 5 additions & 0 deletions .changeset/smooth-numbers-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-css": patch
---

:bug: Modal: Hindre at elementer med sr-only posisjoneres feil
1 change: 1 addition & 0 deletions @navikt/core/css/modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
padding: var(--a-spacing-6);
overflow: auto;
overscroll-behavior: contain;
position: relative; /* Needed to make sr-only elements position correctly - see Storybook */
}

.navds-modal__header + .navds-modal__body {
Expand Down
49 changes: 48 additions & 1 deletion @navikt/core/react/src/modal/modal.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { FileIcon } from "@navikt/aksel-icons";
import { Meta, StoryFn } from "@storybook/react";
import React, { useRef, useState } from "react";
import { FileIcon } from "@navikt/aksel-icons";
import { BodyLong, Button, Heading, Tooltip } from "..";
import { Checkbox, CheckboxGroup } from "../form/checkbox";
import { VStack } from "../layout/stack";
import Modal from "./Modal";

const meta: Meta<typeof Modal> = {
Expand Down Expand Up @@ -203,6 +205,51 @@ export const WithTooltip: StoryFn = () => {
);
};

export const WithSrOnlyElement: StoryFn = () => (
<Modal open width={300} header={{ heading: "Simple header" }}>
<Modal.Body>
<VStack gap="16">
<BodyLong>
The modal body needs to have position:relative to make sr-only
elements position themselves correctly when the modal body is
overflowing (i.e. has a scrollbar).
</BodyLong>
<BodyLong>
If the modal body (and other parents of the sr-only element inside the
modal body) does not have position:relative (or equivalent), the
sr-only element is pushed downwards relative to the height of the
overflowing content.
</BodyLong>
<BodyLong>
In the most extreme cases, an additional scrollbar appears bc. the
dialog element (parent of modal body) starts overflowing. (We have
overflow:auto on the dialog element in case you are on a small screen
and header/footer has a lot of content.)
</BodyLong>
<BodyLong>Example: CheckboxGroup with a hidden legend:</BodyLong>
<CheckboxGroup legend="What fruits do you like?" hideLegend>
<Checkbox>Banana</Checkbox>
<Checkbox>Apple</Checkbox>
<Checkbox>Orange</Checkbox>
<Checkbox>Pear</Checkbox>
</CheckboxGroup>
<BodyLong>
Try to remove position:relative from the modal body and see what
happens. (Use DevTools to find the legend element.) You might need to
make the viewport shorter to get the full effect (double scrollbar).
</BodyLong>
<BodyLong>
Note: The large amount of gap has been added on purpose to force
overflow.
</BodyLong>
</VStack>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary">Dummy button</Button>
</Modal.Footer>
</Modal>
);

export const ChromaticViewportTesting: StoryFn = () => (
<div id="modal-story-wrapper" style={{ width: "100vw", height: "100vh" }}>
<style>{`#storybook-root { padding: 0 !important }`}</style>
Expand Down
Loading