From efc1446fb988b540408c8c80841b6b7b22602cbd Mon Sep 17 00:00:00 2001
From: Ken <26967723+KenAJoh@users.noreply.github.com>
Date: Fri, 29 Nov 2024 11:56:34 +0100
Subject: [PATCH] :memo: Changeset (#3414)
---
.changeset/red-trains-sit.md | 5 ++
.../action-menu/ActionMenu.stories.tsx | 46 +++++++++++
.../src/overlays/action-menu/ActionMenu.tsx | 78 +++++++++++--------
3 files changed, 96 insertions(+), 33 deletions(-)
create mode 100644 .changeset/red-trains-sit.md
diff --git a/.changeset/red-trains-sit.md b/.changeset/red-trains-sit.md
new file mode 100644
index 0000000000..fd15c52b47
--- /dev/null
+++ b/.changeset/red-trains-sit.md
@@ -0,0 +1,5 @@
+---
+"@navikt/ds-react": minor
+---
+
+ActionMenu: Added 'align'-prop to 'ActionMenu.Content'. This allows menu to 'start' or 'end' align in reference to anchor.
diff --git a/@navikt/core/react/src/overlays/action-menu/ActionMenu.stories.tsx b/@navikt/core/react/src/overlays/action-menu/ActionMenu.stories.tsx
index a81ba76bf4..f35920b54f 100644
--- a/@navikt/core/react/src/overlays/action-menu/ActionMenu.stories.tsx
+++ b/@navikt/core/react/src/overlays/action-menu/ActionMenu.stories.tsx
@@ -560,6 +560,48 @@ export const Links: Story = {
decorators: [DemoDecorator],
};
+export const Align: Story = {
+ render: (props) => {
+ return (
+
+
+
+
+
+
+ console.log("Item 1 clicked")}>
+ Item 1
+
+ console.log("Item 2 clicked")}>
+ Item 2
+
+ console.log("Item 3 clicked")}>
+ Item 3
+
+
+
+
+
+
+
+
+ console.log("Item 1 clicked")}>
+ Item 1
+
+ console.log("Item 2 clicked")}>
+ Item 2
+
+ console.log("Item 3 clicked")}>
+ Item 3
+
+
+
+
+ );
+ },
+ decorators: [DemoDecorator],
+};
+
export const Chromatic: Story = {
render: (args, context) => {
const newArgs = { ...args, open: true };
@@ -608,6 +650,10 @@ export const Chromatic: Story = {
{Disabled.render?.(newArgs, context)}
+
+
Align
+ {Align.render?.(newArgs, context)}
+
);
},
diff --git a/@navikt/core/react/src/overlays/action-menu/ActionMenu.tsx b/@navikt/core/react/src/overlays/action-menu/ActionMenu.tsx
index d8ccf9c18d..c159cd0ccc 100644
--- a/@navikt/core/react/src/overlays/action-menu/ActionMenu.tsx
+++ b/@navikt/core/react/src/overlays/action-menu/ActionMenu.tsx
@@ -333,44 +333,56 @@ export const ActionMenuTrigger = forwardRef<
interface ActionMenuContentProps
extends Omit, "id"> {
children?: React.ReactNode;
+ align?: "start" | "end";
}
export const ActionMenuContent = forwardRef<
HTMLDivElement,
ActionMenuContentProps
->(({ children, className, style, ...rest }: ActionMenuContentProps, ref) => {
- const context = useActionMenuContext();
+>(
+ (
+ {
+ children,
+ className,
+ style,
+ align = "start",
+ ...rest
+ }: ActionMenuContentProps,
+ ref,
+ ) => {
+ const context = useActionMenuContext();
- return (
-
- {
- context.triggerRef.current?.focus();
- }}
- safeZone={{ anchor: context.triggerRef.current }}
- style={{
- ...style,
- ...{
- "--__ac-action-menu-content-transform-origin":
- "var(--ac-floating-transform-origin)",
- "--__ac-action-menu-content-available-height":
- "var(--ac-floating-available-height)",
- },
- }}
- >
- {children}
-
-
- );
-});
+ return (
+
+ {
+ context.triggerRef.current?.focus();
+ }}
+ safeZone={{ anchor: context.triggerRef.current }}
+ style={{
+ ...style,
+ ...{
+ "--__ac-action-menu-content-transform-origin":
+ "var(--ac-floating-transform-origin)",
+ "--__ac-action-menu-content-available-height":
+ "var(--ac-floating-available-height)",
+ },
+ }}
+ >
+ {children}
+
+
+ );
+ },
+);
/* -------------------------------------------------------------------------- */
/* ActionMenuLabel */
@@ -977,11 +989,11 @@ ActionMenu.SubTrigger = ActionMenuSubTrigger;
ActionMenu.SubContent = ActionMenuSubContent;
export type {
- ActionMenuItemProps,
ActionMenuCheckboxItemProps,
ActionMenuContentProps,
ActionMenuDividerProps,
ActionMenuGroupProps,
+ ActionMenuItemProps,
ActionMenuLabelProps,
ActionMenuProps,
ActionMenuRadioGroupProps,