diff --git a/docs/guide/building-menu.md b/docs/guide/building-menu.md
index 76cebd133..e3acf19c5 100644
--- a/docs/guide/building-menu.md
+++ b/docs/guide/building-menu.md
@@ -72,6 +72,18 @@ class MySharpMenu extends Code16\Sharp\Utils\Menu\SharpMenu
}
```
+You can open the link in a new tab using the `openInNewTab` parameter:
+
+```php
+class MySharpMenu extends Code16\Sharp\Utils\Menu\SharpMenu
+{
+ public function build(): self
+ {
+ return $this->addExternalLink('https://google.com', 'Some external link', openInNewTab: true);
+ }
+}
+```
+
### Define icons
Yon can specify a [blade-icons](https://blade-ui-kit.com/blade-icons) name for each link. It can be an icon set coming from a [package](https://github.com/blade-ui-kit/blade-icons?tab=readme-ov-file#icon-packages) or defined in the project config.
diff --git a/resources/js/Layouts/Layout.vue b/resources/js/Layouts/Layout.vue
index 258ebc327..a89843188 100644
--- a/resources/js/Layouts/Layout.vue
+++ b/resources/js/Layouts/Layout.vue
@@ -205,7 +205,7 @@
-
+
diff --git a/resources/js/components/MenuItem.vue b/resources/js/components/MenuItem.vue
index baf9ca962..043412600 100644
--- a/resources/js/components/MenuItem.vue
+++ b/resources/js/components/MenuItem.vue
@@ -26,7 +26,7 @@
-
+
{{ item.label }}
diff --git a/resources/js/types/generated.d.ts b/resources/js/types/generated.d.ts
index a597cb7f6..89fdc973a 100644
--- a/resources/js/types/generated.d.ts
+++ b/resources/js/types/generated.d.ts
@@ -745,6 +745,7 @@ export type MenuItemData = {
current: boolean;
children: Array | null;
isCollapsible: boolean;
+ openInNewTab: boolean;
};
export type NotificationData = {
title: string;
diff --git a/src/Data/MenuItemData.php b/src/Data/MenuItemData.php
index f5ecd0158..23f16584d 100644
--- a/src/Data/MenuItemData.php
+++ b/src/Data/MenuItemData.php
@@ -28,6 +28,7 @@ public function __construct(
/** @var MenuItemData[]|null */
public ?array $children = null,
public bool $isCollapsible = false,
+ public bool $openInNewTab = false,
) {}
public static function from(SharpMenuItem $item)
@@ -63,6 +64,7 @@ public static function from(SharpMenuItem $item)
isExternalLink: $item->isExternalLink(),
entityKey: $item->isEntity() ? $item->getEntityKey() : null,
current: $item->isEntity() && $item->isCurrent(),
+ openInNewTab: $item->isOpenInNewTab(),
);
}
diff --git a/src/Utils/Menu/HasSharpMenuItems.php b/src/Utils/Menu/HasSharpMenuItems.php
index f79ad278b..17353fe79 100644
--- a/src/Utils/Menu/HasSharpMenuItems.php
+++ b/src/Utils/Menu/HasSharpMenuItems.php
@@ -36,8 +36,9 @@ public function addExternalLink(
?Closure $badge = null,
?string $badgeTooltip = null,
string|SharpLinkTo|null $badgeLink = null,
+ bool $openInNewTab = false,
): self {
- $this->items[] = (new SharpMenuItemLink($label, $icon, $badge, $badgeTooltip, $badgeLink))
+ $this->items[] = (new SharpMenuItemLink($label, $icon, $badge, $badgeTooltip, $badgeLink, $openInNewTab))
->setUrl($url);
return $this;
diff --git a/src/Utils/Menu/SharpMenuItemLink.php b/src/Utils/Menu/SharpMenuItemLink.php
index d720be255..904c2f08c 100644
--- a/src/Utils/Menu/SharpMenuItemLink.php
+++ b/src/Utils/Menu/SharpMenuItemLink.php
@@ -21,6 +21,7 @@ public function __construct(
protected ?Closure $badge,
protected ?string $badgeTooltip = null,
protected string|SharpLinkTo|null $badgeLink = null,
+ protected bool $openInNewTab = false,
) {}
public function setEntity(string $entityKey): self
@@ -121,4 +122,9 @@ public function isCurrent(): bool
return $this->isEntity() && $rootEntityKey === $this->getEntityKey();
}
+
+ public function isOpenInNewTab(): bool
+ {
+ return $this->openInNewTab;
+ }
}