Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #122 from Ultimaker/fix-context-menu
Browse files Browse the repository at this point in the history
fix context menu direction
  • Loading branch information
DanielSchiavini authored Dec 21, 2018
2 parents bdce1ca + 2d2b6f0 commit a814844
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

exports[`The ContextMenu component should render 1`] = `
<div
className="context-menu context-menu--south"
className="context-menu"
>
<DropDownMenuBase
menuDirection="south"
menuStyle={
Object {
"right": -30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports[`The DropDownMenu component should render 1`] = `
className="drop-down-menu"
>
<DropDownMenuBase
menuDirection="south"
onToggleMenuHandler={[Function]}
showMenu={false}
triggerElement={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`The DropDownMenuBase component should render 1`] = `
<div
className="drop-down-menu-base"
className="drop-down-menu-base drop-down-menu-base--south"
onClick={[Function]}
>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports[`The UserAccountMenu component should display other section 1`] = `
className="user-account-menu"
>
<DropDownMenuBase
menuDirection="south"
onToggleMenuHandler={[Function]}
showMenu={false}
triggerElement={
Expand Down Expand Up @@ -92,6 +93,7 @@ exports[`The UserAccountMenu component should render 1`] = `
className="user-account-menu"
>
<DropDownMenuBase
menuDirection="south"
onToggleMenuHandler={[Function]}
showMenu={false}
triggerElement={
Expand Down Expand Up @@ -169,6 +171,7 @@ exports[`The UserAccountMenu component should render sign in button 1`] = `
className="user-account-menu"
>
<DropDownMenuBase
menuDirection="south"
onToggleMenuHandler={[Function]}
showMenu={true}
triggerElement={
Expand Down
3 changes: 1 addition & 2 deletions src/components/__tests__/context_menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ describe('The ContextMenu component', () => {

it('should render to north', () => {
wrapper.setProps({ menuDirection: 'north' });
expect(wrapper.find('.context-menu--north')).toHaveLength(1);
expect(wrapper.find('.context-menu--south').exists()).toBe(false);
expect(wrapper.find(DropDownMenuBase).prop('menuDirection')).toBe('north');
});

it('should render for a panel', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/context_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import * as React from 'react';
import classNames from 'classnames';

// components
import DropDownMenuBase from './drop_down_menu_base';
import { DropDownMenuBase, MenuDirection } from './drop_down_menu_base';

export type MenuOffsetDirection = 'left' | 'right';
export type MenuDirection = 'north' | 'south';

export interface ContextMenuProps {
/** Width of the menu in pixels */
Expand Down Expand Up @@ -119,7 +118,7 @@ export class ContextMenu extends React.Component<ContextMenuProps, ContextMenuSt
const { menuOffset, showMenu } = this.state;

const classes = classNames(
`context-menu context-menu--${menuDirection}`,
'context-menu',
{ 'context-menu--panel': positionMenuInPanel },
);
const menuStyle = ContextMenu._getMenuStyle(menuOffset, menuOffsetDirection, menuWidth);
Expand All @@ -132,6 +131,7 @@ export class ContextMenu extends React.Component<ContextMenuProps, ContextMenuSt
triggerElement={<div style={{ width: triggerWidth }} />}
menuStyle={menuStyle}
onToggleMenuHandler={newShowMenu => this._onToggleMenuHandler(newShowMenu)}
menuDirection={menuDirection}
>
{children}
</DropDownMenuBase>
Expand Down
6 changes: 5 additions & 1 deletion src/components/drop_down_menu_base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Collapse } from 'react-collapse';
// components
import Button from './button';

export type MenuDirection = 'left' | 'right';
export type MenuDirection = 'north' | 'south';

export interface DropDownMenuBaseProps {
/** Whether the menu should be visible */
Expand All @@ -23,6 +23,10 @@ export interface DropDownMenuBaseProps {
}

export class DropDownMenuBase extends React.Component<DropDownMenuBaseProps, {}> {
public static defaultProps: Partial<DropDownMenuBaseProps> = {
menuDirection: 'south',
};

static _stopPropagation(e): void {
e.stopPropagation();
}
Expand Down
4 changes: 2 additions & 2 deletions src/stories/menu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const offsetOptions = {
const offsetDefaultValue = 'left';

const directionOptions = {
Left: 'north',
Right: 'south',
North: 'north',
South: 'south',
};
const directionDefaultValue = 'south';

Expand Down
1 change: 0 additions & 1 deletion src/stylesheets/_context_menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
top: 0;
right: 0;
bottom: 0;
left: 0;

.drop-down-menu-base {
height: 100%;
Expand Down

0 comments on commit a814844

Please sign in to comment.