Skip to content

Commit

Permalink
fix(Dropdown): better dynamic attributes for VDropdownItem
Browse files Browse the repository at this point in the history
  • Loading branch information
gravitano committed Aug 2, 2023
1 parent 07c6790 commit d1f1a80
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
20 changes: 18 additions & 2 deletions packages/dropdown/src/Dropdown.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,25 @@ export const RouterLink = Template.bind({});
RouterLink.args = {
items: [
{
text: 'Link 1',
text: 'Home',
to: '/home',
},
{
text: 'Profile',
to: '/profile',
},
{
text: 'Settings',
to: '/settings',
},
{
divider: true,
},
{
text: 'Go to Google',
href: 'https://google.com',
newTab: true,
},
],
};

Expand Down Expand Up @@ -179,4 +195,4 @@ export const FloatingUI: Story = (args, {argTypes}) => ({
});
FloatingUI.parameters = {
layout: 'centered',
};
};
36 changes: 32 additions & 4 deletions packages/dropdown/src/DropdownItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const props = withDefaults(
newTab?: boolean;
divider?: boolean;
nuxt?: boolean;
disabled?: boolean;
}>(),
{
iconClass: '',
Expand All @@ -30,15 +31,42 @@ const computedComponent = computed(() => {
});
const attributes = computed(() => {
let attrs: Record<string, any> = {};
if (props.disabled) {
attrs['aria-disabled'] = true;
attrs['disabled'] = true;
}
if (props.to) {
attrs['to'] = props.to;
}
if (props.href) {
attrs['href'] = props.href;
}
if (props.newTab) {
attrs['rel'] = 'noopener';
attrs['target'] = '_blank';
}
return {
to: props.to ?? undefined,
href: props.href ?? undefined,
target: props.href && props.newTab ? '_blank' : undefined,
rel: props.href && props.newTab ? 'noopener' : undefined,
...attrs,
...useAttrs(),
};
});
// const attributes = computed(() => {
// return {
// to: props.to ?? undefined,
// href: props.href ?? undefined,
// target: props.href && props.newTab ? '_blank' : undefined,
// rel: props.href && props.newTab ? 'noopener' : undefined,
// ...useAttrs(),
// };
// });
defineSlots<{
default?: (props: {}) => any;
icon?: (props: {}) => any;
Expand Down

0 comments on commit d1f1a80

Please sign in to comment.