-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Context menu upgrade from v1.6.2 to v2.9.2 (#1081)
* upgrade react context menu to v2.9 * add unit tests * update unit test * remove unecessary id set * remove unnecessary function * update migration doc
- Loading branch information
Showing
7 changed files
with
142 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import {MenuItem, monitor, SubMenu, connect, ContextMenuLayer} from 'react-contextmenu'; | ||
import ContextMenu from './ContextMenu'; | ||
import {ContextMenu, MenuItem, monitor, SubMenu, connect, ContextMenuTrigger} from 'react-contextmenu'; | ||
import MenuHeader from './MenuHeader'; | ||
|
||
export {ContextMenu, MenuHeader, MenuItem, monitor, SubMenu, connect, ContextMenuLayer}; | ||
export {ContextMenu, MenuHeader, MenuItem, monitor, SubMenu, connect, ContextMenuTrigger}; |
59 changes: 45 additions & 14 deletions
59
packages/react-data-grid-examples/src/assets/css/react-context-menu.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,78 @@ | ||
.react-context-menu { | ||
.react-contextmenu { | ||
min-width: 160px; | ||
padding: 5px 0; | ||
margin: 2px 0 0; | ||
font-size: 14px; | ||
font-size: 16px; | ||
color: #373a3c; | ||
text-align: left; | ||
background-color: #fff; | ||
-webkit-background-clip: padding-box; | ||
background-clip: padding-box; | ||
border: 1px solid rgba(0,0,0,.15); | ||
border-radius: .25rem; | ||
outline: none; | ||
opacity: 0; | ||
pointer-events: none; | ||
transition: opacity 250ms ease !important; | ||
} | ||
|
||
.react-context-menu-link { | ||
display: inline-block; | ||
width: 100%; | ||
.react-contextmenu.react-contextmenu--visible { | ||
opacity: 1; | ||
pointer-events: auto; | ||
} | ||
|
||
.react-contextmenu-item { | ||
padding: 3px 20px; | ||
clear: both; | ||
font-weight: 400; | ||
line-height: 1.5; | ||
color: #373a3c; | ||
text-align: inherit; | ||
white-space: nowrap; | ||
background: 0 0; | ||
border: 0; | ||
cursor: pointer; | ||
} | ||
|
||
.react-context-menu-link.active, | ||
.react-context-menu-link:hover { | ||
.react-contextmenu-item.react-contextmenu-item--active, | ||
.react-contextmenu-item.react-contextmenu-item--selected { | ||
color: #fff; | ||
background-color: #0275d8; | ||
border-color: #0275d8; | ||
background-color: #20a0ff; | ||
border-color: #20a0ff; | ||
text-decoration: none; | ||
} | ||
|
||
.react-context-menu-item.submenu > a { | ||
padding-right: 27px; | ||
.react-contextmenu-item.react-contextmenu-item--disabled, | ||
.react-contextmenu-item.react-contextmenu-item--disabled:hover { | ||
color: #878a8c; | ||
background-color: transparent; | ||
border-color: rgba(0,0,0,.15); | ||
} | ||
|
||
.react-contextmenu-item--divider { | ||
margin-bottom: 3px; | ||
padding: 2px 0; | ||
border-bottom: 1px solid rgba(0,0,0,.15); | ||
cursor: inherit; | ||
} | ||
.react-contextmenu-item--divider:hover { | ||
background-color: transparent; | ||
border-color: rgba(0,0,0,.15); | ||
} | ||
|
||
.react-context-menu-item.submenu > a:after { | ||
.react-contextmenu-item.react-contextmenu-submenu { | ||
padding: 0; | ||
} | ||
|
||
.react-contextmenu-item.react-contextmenu-submenu > .react-contextmenu-item { | ||
} | ||
|
||
.react-contextmenu-item.react-contextmenu-submenu > .react-contextmenu-item:after { | ||
content: "▶"; | ||
display: inline-block; | ||
position: absolute; | ||
right: 7px; | ||
} | ||
|
||
.example-multiple-targets::after { | ||
content: attr(data-count); | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 52 additions & 7 deletions
59
packages/react-data-grid/src/__tests__/RowsContainer.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,62 @@ | ||
import { shallow } from 'enzyme'; | ||
import React from 'react'; | ||
import ReactTestUtils from 'react-dom/test-utils'; | ||
import RowsContainer from '../RowsContainer'; | ||
import RowsContainer, { getNewContextMenuProps, SimpleRowsContainer, DEFAULT_CONTEXT_MENU_ID } from '../RowsContainer'; | ||
|
||
const FakeContextMenuTrigger = () => <div id="fakeContextMenuTrigger" />; | ||
|
||
const FakeContextMenu = () => <div />; | ||
|
||
const ReactDataGridPlugins = { | ||
Menu: { | ||
ContextMenuTrigger: FakeContextMenuTrigger | ||
} | ||
}; | ||
|
||
const contextMenuId = 'fakeContextMenu'; | ||
const props = { | ||
contextMenu: <FakeContextMenu id={contextMenuId} />, | ||
rowIdx: 5, | ||
idx: 8, | ||
window: { ReactDataGridPlugins }, | ||
rows: [ | ||
{ id: 'row_1' }, | ||
{ id: 'row_2' } | ||
] | ||
}; | ||
|
||
describe('Rows Container', () => { | ||
describe('without context menu', () => { | ||
let componentWithoutContextMenu = {}; | ||
describe('getNewContextMenuProps()', () => { | ||
it('should populate correct newProps for contextMenu with customized menu id', () => { | ||
const newProps = getNewContextMenuProps(props); | ||
expect(newProps.id).toBe(contextMenuId); | ||
}); | ||
|
||
beforeEach(() => { | ||
componentWithoutContextMenu = ReactTestUtils.renderIntoDocument(<RowsContainer window={{ ReactDataGridPlugins: undefined }} />); | ||
it('should populate correct newProps for contextMenu with default menu id', () => { | ||
const newProps = getNewContextMenuProps(Object.assign({}, props, { contextMenu: <FakeContextMenu /> })); | ||
expect(newProps.id).toBe(DEFAULT_CONTEXT_MENU_ID); | ||
}); | ||
}); | ||
|
||
describe('with context menu', () => { | ||
it('should create a new RowsContainer instance', () => { | ||
expect(componentWithoutContextMenu).toBeDefined(); | ||
const wrapper = shallow(<RowsContainer {...props} />); | ||
expect(wrapper.find(FakeContextMenuTrigger).length).toBe(1); | ||
}); | ||
|
||
it('should throw exception for no context menu plugin when rendering', () => { | ||
const newProp = Object.assign({}, props, { window: {}}); | ||
expect(() => { shallow(<RowsContainer {...newProp} />); }).toThrowError('You need to include ReactDataGrid UiPlugins in order to initialise context menu'); | ||
}); | ||
}); | ||
|
||
describe('without context menu', () => { | ||
it('should create a SimpleRowsContainer', () => { | ||
const newProps = Object.assign({}, props, { | ||
contextMenu: undefined | ||
}); | ||
const wrapper = shallow(<RowsContainer {...newProps}/>); | ||
expect(wrapper.find(SimpleRowsContainer).length).toBe(1); | ||
expect(wrapper.find(FakeContextMenuTrigger).length).toBe(0); | ||
}); | ||
}); | ||
}); |