Skip to content

Commit

Permalink
feat(vue-dropdown): add align-y-menu property
Browse files Browse the repository at this point in the history
  • Loading branch information
devCrossNet committed Aug 11, 2021
1 parent cb18815 commit fa9809d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Expand Up @@ -96,13 +96,14 @@ describe('VueDropdown.vue', () => {
test('renders component with different menu alignment', async () => {
const { getByText, getByTestId, updateProps } = harness;

await updateProps({ alignMenu: 'right' });
await updateProps({ alignMenu: 'right', alignYMenu: 'top' });

getByText('Dropdown');

await fireEvent.click(getByText('Dropdown'));
const menu = getByTestId('menu');

expect(menu.classList.contains('right')).toBeTruthy();
expect(menu.classList.contains('top')).toBeTruthy();
});
});
Expand Up @@ -13,7 +13,7 @@ story.add(
'Default',
() => ({
components: { VueDropdown, ComponentDocs, VueStack, VueInline, VueSelect },
data(): { items: Array<IItem>; alignMenu: IItem; size: IItem } {
data(): { items: Array<IItem>; alignMenu: IItem; alignYMenu: IItem; size: IItem } {
return {
items: [
{ label: 'Save', value: 'save', leadingIcon: 'save' },
Expand All @@ -22,6 +22,7 @@ story.add(
{ label: 'Delete', value: 'delete', leadingIcon: 'trash' },
],
alignMenu: { label: 'Left', value: 'left' },
alignYMenu: { label: 'Bottom', value: 'bottom' },
size: { label: 'Medium', value: 'md' },
};
},
Expand All @@ -38,12 +39,23 @@ story.add(
{ label: 'Center', value: 'center' },
{ label: 'Right', value: 'right' },
]"
label="Align menu"
label="Align menu horizontally"
name="alignMenu"
id="alignMenu"
hide-description
v-model="alignMenu"
/>
<vue-select
:items="[
{ label: 'Top', value: 'top' },
{ label: 'Bottom', value: 'bottom' },
]"
label="Align menu vertically"
name="alignYMenu"
id="alignYMenu"
hide-description
v-model="alignYMenu"
/>
<vue-select
:items="[
{ label: 'Small', value: 'sm' },
Expand All @@ -62,6 +74,7 @@ story.add(
button-text="Dropdown Button"
:items="items"
:align-menu="alignMenu.value"
:align-y-menu="alignYMenu.value"
:size="size.value"
@click="onClick"
@item-click="onItemClick" />
Expand Down
12 changes: 11 additions & 1 deletion src/components/input-and-actions/VueDropdown/VueDropdown.vue
Expand Up @@ -12,7 +12,7 @@
<vue-menu
ref="menuRef"
:items="items"
:class="[$style.menu, $style[alignMenu], $style[size]]"
:class="[$style.menu, $style[alignMenu], $style[alignYMenu], $style[size]]"
@click="onItemClick"
/>
</vue-collapse>
Expand All @@ -37,6 +37,7 @@ export default defineComponent({
items: { type: Array as new () => IItem[], required: true },
duration: { type: Number, default: 250 },
alignMenu: { type: String, validator: horizontalAlignmentValidator, default: 'left' },
alignYMenu: { type: String, validator: (value: string) => ['top', 'bottom'].includes(value), default: 'bottom' },
size: { type: String, validator: shirtSizeValidator, default: 'md' },
},
setup(_, { emit }) {
Expand Down Expand Up @@ -122,6 +123,15 @@ export default defineComponent({
&.right {
right: 0;
}
&.top {
top: -$dropdown-button-menu-gap;
transform: translateY(-100%);
&.center {
transform: translate(-50%, -100%);
}
}
}
}
</style>

0 comments on commit fa9809d

Please sign in to comment.