Skip to content

Commit 5524f78

Browse files
committed
fix(Dialog): component now respects reduced motion preferences
1 parent 0f86381 commit 5524f78

File tree

1 file changed

+2
-6
lines changed
  • packages/orbit-components/src/Dialog

1 file changed

+2
-6
lines changed

packages/orbit-components/src/Dialog/index.tsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import Heading from "../Heading";
1010
import Text from "../Text";
1111
import Stack from "../Stack";
1212
import useLockScrolling from "../hooks/useLockScrolling";
13-
import KEY_CODE_MAP from "../common/keyMaps";
1413
import useClickOutside from "../hooks/useClickOutside";
1514
import useRandomId from "../hooks/useRandomId";
1615
import type { Props } from "./types";
@@ -41,21 +40,19 @@ const Dialog = ({
4140
useLockScrolling(wrapperRef, lockScrolling);
4241
const ref = React.useRef<HTMLDivElement | null>(null);
4342
const theme = useTheme();
44-
const [shown, setShown] = React.useState(false);
4543

4644
useFocusTrap(ref);
4745

4846
React.useEffect(() => {
4947
const transitionLength = parseFloat(theme.orbit.durationFast) * 1000;
5048
const timer = setTimeout(() => {
51-
setShown(true);
5249
if (ref.current) {
5350
ref.current.focus();
5451
}
5552
}, transitionLength);
5653

5754
const handleKeyDown = (ev: KeyboardEvent) => {
58-
if (ev.keyCode === KEY_CODE_MAP.ESC && onClose) {
55+
if (ev.key === "Escape" && onClose) {
5956
onClose();
6057
}
6158
};
@@ -99,7 +96,7 @@ const Dialog = ({
9996
"size-full",
10097
"p-400 z-overlay box-border overflow-x-hidden bg-[rgba(0,0,0,0.5)]",
10198
"fixed inset-0",
102-
"duration-fast transition-opacity ease-in-out",
99+
"motion-safe:duration-fast motion-safe:transition-opacity motion-safe:ease-in-out",
103100
"lm:opacity-100 lm:flex lm:items-center lm:justify-center",
104101
])}
105102
>
@@ -110,7 +107,6 @@ const Dialog = ({
110107
style={{ maxWidth }}
111108
className={cx([
112109
"shadow-level4 pt-600 px-400 pb-400 bg-white-normal rounded-dialog-mobile box-border block w-full",
113-
shown ? "bottom-0" : "-bottom-full",
114110
"lm:min-w-dialog-width lm:p-600 lm:rounded-dialog-desktop",
115111
])}
116112
>

0 commit comments

Comments
 (0)