fix(editor): Use web native <a> element in nav menus (#8385)
This commit is contained in:
@@ -75,10 +75,9 @@ link.args = {
|
||||
id: 'website',
|
||||
icon: 'globe',
|
||||
label: 'Website',
|
||||
type: 'link',
|
||||
properties: {
|
||||
link: {
|
||||
href: 'https://www.n8n.io',
|
||||
newWindow: true,
|
||||
target: '_blank',
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -96,10 +95,9 @@ withChildren.args = {
|
||||
id: 'quickstart',
|
||||
icon: 'video',
|
||||
label: 'Quickstart',
|
||||
type: 'link',
|
||||
properties: {
|
||||
link: {
|
||||
href: 'https://www.youtube.com/watch?v=RpjQTGKm-ok',
|
||||
newWindow: true,
|
||||
target: '_blank',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -40,37 +40,39 @@
|
||||
:disabled="!compact"
|
||||
:show-after="tooltipDelay"
|
||||
>
|
||||
<ElMenuItem
|
||||
:id="item.id"
|
||||
:class="{
|
||||
[$style.menuItem]: true,
|
||||
[$style.item]: true,
|
||||
[$style.disableActiveStyle]: !isItemActive(item),
|
||||
[$style.active]: isItemActive(item),
|
||||
[$style.compact]: compact,
|
||||
}"
|
||||
data-test-id="menu-item"
|
||||
:index="item.id"
|
||||
@click="handleSelect(item)"
|
||||
>
|
||||
<N8nIcon
|
||||
v-if="item.icon"
|
||||
:class="$style.icon"
|
||||
:icon="item.icon"
|
||||
:size="item.customIconSize || 'large'"
|
||||
/>
|
||||
<span :class="$style.label">{{ item.label }}</span>
|
||||
<N8nTooltip
|
||||
v-if="item.secondaryIcon"
|
||||
:class="$style.secondaryIcon"
|
||||
:placement="item.secondaryIcon?.tooltip?.placement || 'right'"
|
||||
:content="item.secondaryIcon?.tooltip?.content"
|
||||
:disabled="compact || !item.secondaryIcon?.tooltip?.content"
|
||||
:show-after="tooltipDelay"
|
||||
<ConditionalRouterLink v-bind="item.route ?? item.link">
|
||||
<ElMenuItem
|
||||
:id="item.id"
|
||||
:class="{
|
||||
[$style.menuItem]: true,
|
||||
[$style.item]: true,
|
||||
[$style.disableActiveStyle]: !isItemActive(item),
|
||||
[$style.active]: isItemActive(item),
|
||||
[$style.compact]: compact,
|
||||
}"
|
||||
data-test-id="menu-item"
|
||||
:index="item.id"
|
||||
@click="handleSelect(item)"
|
||||
>
|
||||
<N8nIcon :icon="item.secondaryIcon.name" :size="item.secondaryIcon.size || 'small'" />
|
||||
</N8nTooltip>
|
||||
</ElMenuItem>
|
||||
<N8nIcon
|
||||
v-if="item.icon"
|
||||
:class="$style.icon"
|
||||
:icon="item.icon"
|
||||
:size="item.customIconSize || 'large'"
|
||||
/>
|
||||
<span :class="$style.label">{{ item.label }}</span>
|
||||
<N8nTooltip
|
||||
v-if="item.secondaryIcon"
|
||||
:class="$style.secondaryIcon"
|
||||
:placement="item.secondaryIcon?.tooltip?.placement || 'right'"
|
||||
:content="item.secondaryIcon?.tooltip?.content"
|
||||
:disabled="compact || !item.secondaryIcon?.tooltip?.content"
|
||||
:show-after="tooltipDelay"
|
||||
>
|
||||
<N8nIcon :icon="item.secondaryIcon.name" :size="item.secondaryIcon.size || 'small'" />
|
||||
</N8nTooltip>
|
||||
</ElMenuItem>
|
||||
</ConditionalRouterLink>
|
||||
</N8nTooltip>
|
||||
</div>
|
||||
</template>
|
||||
@@ -81,7 +83,9 @@ import N8nTooltip from '../N8nTooltip';
|
||||
import N8nIcon from '../N8nIcon';
|
||||
import type { PropType } from 'vue';
|
||||
import { defineComponent } from 'vue';
|
||||
import ConditionalRouterLink from '../ConditionalRouterLink';
|
||||
import type { IMenuItem, RouteObject } from '../../types';
|
||||
import { doesMenuItemMatchCurrentRoute } from './routerUtil';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'N8nMenuItem',
|
||||
@@ -90,6 +94,7 @@ export default defineComponent({
|
||||
ElMenuItem,
|
||||
N8nIcon,
|
||||
N8nTooltip,
|
||||
ConditionalRouterLink,
|
||||
},
|
||||
props: {
|
||||
item: {
|
||||
@@ -115,9 +120,11 @@ export default defineComponent({
|
||||
},
|
||||
activeTab: {
|
||||
type: String,
|
||||
default: undefined,
|
||||
},
|
||||
handleSelect: {
|
||||
type: Function as PropType<(item: IMenuItem) => void>,
|
||||
default: undefined,
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
@@ -151,18 +158,7 @@ export default defineComponent({
|
||||
},
|
||||
isActive(item: IMenuItem): boolean {
|
||||
if (this.mode === 'router') {
|
||||
if (item.activateOnRoutePaths) {
|
||||
return (
|
||||
Array.isArray(item.activateOnRoutePaths) &&
|
||||
item.activateOnRoutePaths.includes(this.currentRoute.path)
|
||||
);
|
||||
} else if (item.activateOnRouteNames) {
|
||||
return (
|
||||
Array.isArray(item.activateOnRouteNames) &&
|
||||
item.activateOnRouteNames.includes(this.currentRoute.name || '')
|
||||
);
|
||||
}
|
||||
return false;
|
||||
return doesMenuItemMatchCurrentRoute(item, this.currentRoute);
|
||||
} else {
|
||||
return item.id === this.activeTab;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import type { IMenuItem, RouteObject } from '@/types';
|
||||
import type { RouteLocationRaw } from 'vue-router';
|
||||
|
||||
/**
|
||||
* Checks if the given menu item matches the current route.
|
||||
*/
|
||||
export function doesMenuItemMatchCurrentRoute(item: IMenuItem, currentRoute: RouteObject) {
|
||||
let activateOnRouteNames: string[] = [];
|
||||
if (Array.isArray(item.activateOnRouteNames)) {
|
||||
activateOnRouteNames = item.activateOnRouteNames;
|
||||
} else if (item.route && isNamedRouteLocation(item.route.to)) {
|
||||
activateOnRouteNames = [item.route.to.name];
|
||||
}
|
||||
|
||||
let activateOnRoutePaths: string[] = [];
|
||||
if (Array.isArray(item.activateOnRoutePaths)) {
|
||||
activateOnRoutePaths = item.activateOnRoutePaths;
|
||||
} else if (item.route && isPathRouteLocation(item.route.to)) {
|
||||
activateOnRoutePaths = [item.route.to.path];
|
||||
}
|
||||
|
||||
return (
|
||||
activateOnRouteNames.includes(currentRoute.name ?? '') ||
|
||||
activateOnRoutePaths.includes(currentRoute.path)
|
||||
);
|
||||
}
|
||||
|
||||
function isPathRouteLocation(routeLocation?: RouteLocationRaw): routeLocation is { path: string } {
|
||||
return (
|
||||
typeof routeLocation === 'object' &&
|
||||
'path' in routeLocation &&
|
||||
typeof routeLocation.path === 'string'
|
||||
);
|
||||
}
|
||||
|
||||
function isNamedRouteLocation(routeLocation?: RouteLocationRaw): routeLocation is { name: string } {
|
||||
return (
|
||||
typeof routeLocation === 'object' &&
|
||||
'name' in routeLocation &&
|
||||
typeof routeLocation.name === 'string'
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user