diff --git a/react/src/lib/ActivityButton/tests/__snapshots__/index.spec.js.snap b/react/src/lib/ActivityButton/tests/__snapshots__/index.spec.js.snap index 20b9299333..49cd2c2b92 100644 --- a/react/src/lib/ActivityButton/tests/__snapshots__/index.spec.js.snap +++ b/react/src/lib/ActivityButton/tests/__snapshots__/index.spec.js.snap @@ -23,11 +23,9 @@ ShallowWrapper { Symbol(enzyme.__node__): Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "test", - "ariaLabelledBy": "", "children": , "circle": true, "className": "md-activity md-activity__chat", - "color": "", + "color": undefined, "containerLarge": false, "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": null, - "removeStyle": false, "size": 68, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -90,17 +77,20 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, Symbol(enzyme.__nodes__): Array [ Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "test", - "ariaLabelledBy": "", "children": , "circle": true, "className": "md-activity md-activity__chat", - "color": "", + "color": undefined, "containerLarge": false, "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": null, - "removeStyle": false, "size": 68, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -163,7 +142,12 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, ], Symbol(enzyme.__options__): Object { diff --git a/react/src/lib/ActivityButton/tests/index.spec.js b/react/src/lib/ActivityButton/tests/index.spec.js index 0cbebec857..f37951d94c 100644 --- a/react/src/lib/ActivityButton/tests/index.spec.js +++ b/react/src/lib/ActivityButton/tests/index.spec.js @@ -10,7 +10,7 @@ describe('tests for ', () => { }); it('should render one ActivityButton button', () => { - const container = shallow(); + const container = mount(); expect(container.find('Button').length).toEqual(1); }); diff --git a/react/src/lib/Alert/tests/__snapshots__/index.spec.js.snap b/react/src/lib/Alert/tests/__snapshots__/index.spec.js.snap index 814009ee60..670927ae7d 100644 --- a/react/src/lib/Alert/tests/__snapshots__/index.spec.js.snap +++ b/react/src/lib/Alert/tests/__snapshots__/index.spec.js.snap @@ -46,28 +46,9 @@ ShallowWrapper {
- +
, ], "className": "md-alert md-alert--info", @@ -157,28 +138,9 @@ ShallowWrapper { "key": undefined, "nodeType": "host", "props": Object { - "children": , + , "className": "md-alert__button", }, "ref": null, "rendered": Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, - "ariaLabel": "", - "ariaLabelledBy": "", "children": , "circle": true, - "className": "", - "color": "", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, - "onClick": null, - "removeStyle": false, "size": 44, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -271,7 +214,12 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, "type": "div", }, @@ -305,28 +253,9 @@ ShallowWrapper {
- +
, ], "className": "md-alert md-alert--info", @@ -416,28 +345,9 @@ ShallowWrapper { "key": undefined, "nodeType": "host", "props": Object { - "children": , + , "className": "md-alert__button", }, "ref": null, "rendered": Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, - "ariaLabel": "", - "ariaLabelledBy": "", "children": , "circle": true, - "className": "", - "color": "", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, - "onClick": null, - "removeStyle": false, "size": 44, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -530,7 +421,12 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, "type": "div", }, diff --git a/react/src/lib/AlertCall/tests/__snapshots__/index.spec.js.snap b/react/src/lib/AlertCall/tests/__snapshots__/index.spec.js.snap index 6a61bd4d3c..b21f7d863c 100644 --- a/react/src/lib/AlertCall/tests/__snapshots__/index.spec.js.snap +++ b/react/src/lib/AlertCall/tests/__snapshots__/index.spec.js.snap @@ -89,28 +89,12 @@ ShallowWrapper {
- +
, ], "className": "md-alert md-alert--call", @@ -262,28 +246,12 @@ ShallowWrapper { null, null, null, - , + , ], "className": "md-alert--call--buttons", }, @@ -314,11 +282,9 @@ ShallowWrapper { Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "reject call", - "ariaLabelledBy": "", "children": , "circle": true, - "className": "", "color": "red", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": null, - "removeStyle": false, "size": 44, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -381,7 +333,12 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, ], "type": "div", @@ -438,28 +395,12 @@ ShallowWrapper {
- +
, ], "className": "md-alert md-alert--call", @@ -611,28 +552,12 @@ ShallowWrapper { null, null, null, - , + , ], "className": "md-alert--call--buttons", }, @@ -663,11 +588,9 @@ ShallowWrapper { Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "reject call", - "ariaLabelledBy": "", "children": , "circle": true, - "className": "", "color": "red", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": null, - "removeStyle": false, "size": 44, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -730,7 +639,12 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, ], "type": "div", @@ -889,28 +803,12 @@ ShallowWrapper {
- +
, ], "className": "md-alert md-alert--call", @@ -1104,28 +1002,12 @@ ShallowWrapper { null, null, null, - , + , ], "className": "md-alert--call--buttons", }, @@ -1156,11 +1038,9 @@ ShallowWrapper { Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "reject call", - "ariaLabelledBy": "", "children": , "circle": true, - "className": "", "color": "red", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": null, - "removeStyle": false, "size": 44, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -1223,7 +1089,12 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, ], "type": "div", @@ -1300,28 +1171,12 @@ ShallowWrapper {
- +
, ], "className": "md-alert md-alert--call", @@ -1515,28 +1370,12 @@ ShallowWrapper { null, null, null, - , + , ], "className": "md-alert--call--buttons", }, @@ -1567,11 +1406,9 @@ ShallowWrapper { Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "reject call", - "ariaLabelledBy": "", "children": , "circle": true, - "className": "", "color": "red", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": null, - "removeStyle": false, "size": 44, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -1634,7 +1457,12 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, ], "type": "div", diff --git a/react/src/lib/AlertMeeting/tests/__snapshots__/index.spec.js.snap b/react/src/lib/AlertMeeting/tests/__snapshots__/index.spec.js.snap index b4db999e90..8eb7e80ad8 100644 --- a/react/src/lib/AlertMeeting/tests/__snapshots__/index.spec.js.snap +++ b/react/src/lib/AlertMeeting/tests/__snapshots__/index.spec.js.snap @@ -88,28 +88,11 @@ ShallowWrapper {
- +
,
- +
, ], "className": "md-alert md-alert--meeting", @@ -282,28 +248,11 @@ ShallowWrapper { "key": undefined, "nodeType": "host", "props": Object { - "children": , + , "className": "md-alert__button", }, "ref": null, "rendered": Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "snooze", - "ariaLabelledBy": "", "children": , "circle": true, - "className": "", - "color": "", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": [Function], - "removeStyle": false, "size": 44, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -396,7 +328,12 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, "type": "div", }, @@ -405,28 +342,11 @@ ShallowWrapper { "key": undefined, "nodeType": "host", "props": Object { - "children": , + , "className": "md-alert__button", }, "ref": null, "rendered": Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "close", - "ariaLabelledBy": "", "children": , "circle": true, - "className": "", - "color": "", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": null, - "removeStyle": false, "size": 44, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -519,7 +422,12 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, "type": "div", }, @@ -577,28 +485,11 @@ ShallowWrapper {
- +
,
- +
, ], "className": "md-alert md-alert--meeting", @@ -771,28 +645,11 @@ ShallowWrapper { "key": undefined, "nodeType": "host", "props": Object { - "children": , + , "className": "md-alert__button", }, "ref": null, "rendered": Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "snooze", - "ariaLabelledBy": "", "children": , "circle": true, - "className": "", - "color": "", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": [Function], - "removeStyle": false, "size": 44, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -885,7 +725,12 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, "type": "div", }, @@ -894,28 +739,11 @@ ShallowWrapper { "key": undefined, "nodeType": "host", "props": Object { - "children": , + , "className": "md-alert__button", }, "ref": null, "rendered": Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "close", - "ariaLabelledBy": "", "children": , "circle": true, - "className": "", - "color": "", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": null, - "removeStyle": false, "size": 44, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -1008,7 +819,12 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, "type": "div", }, diff --git a/react/src/lib/Button/index.js b/react/src/lib/Button/index.js index 1ce713a18f..65899a6974 100644 --- a/react/src/lib/Button/index.js +++ b/react/src/lib/Button/index.js @@ -4,57 +4,38 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Loading } from '@momentum-ui/react'; import omit from 'lodash/omit'; +import { UIDConsumer } from 'react-uid'; +import ButtonGroupContext from '../ButtonGroupContext'; +import SelectableContext, { makeKeyboardKey } from '../SelectableContext'; +import mapContextToProps from 'react-context-toolbox/mapContextToProps'; class Button extends React.Component { - static displayName = 'Button'; - componentDidMount() { /* eslint-disable no-console */ - const { ariaLabel, ariaLabelledBy, index } = this.props; - const { focusIndex, focusOnLoad } = this.context; + const { ariaLabel, ariaLabelledBy } = this.props; (!ariaLabel && !ariaLabelledBy) && console.warn('[@momentum-ui/react] Button: Accessibility could be improved with ariaLabel'); - - focusOnLoad - && focusIndex === index - && this.refs.button.focus(); /* eslint-enable no-console */ } - componentWillUpdate() { - this.prevContext = this.context; - } - - componentDidUpdate () { - const { focusIndex } = this.context; - const { index } = this.props; - - typeof index === 'number' - && index === focusIndex - && focusIndex !== this.prevContext.focusIndex - && this.refs.button.focus(); - } - - handleKeyDown = e => { - const { onClick, index } = this.props; - const { handleKeyDown, handleClick } = this.context; + handleKeyDown = (e, eventKey) => { + const { onClick, parentOnSelect, parentKeyDown } = this.props; if (e.which === 32 || e.which === 13 || e.charCode === 32 || e.charCode === 13) { - handleClick && handleClick(e, index); + parentOnSelect && parentOnSelect(e, { eventKey }); onClick && onClick(e); } else { - handleKeyDown && handleKeyDown(e, index); + parentKeyDown && parentKeyDown(e, eventKey); } }; - handleClick = e => { - const { handleClick } = this.context; - const { index, onClick } = this.props; + handleClick = (e, eventKey) => { + const { onClick, parentOnSelect } = this.props; onClick && onClick(e); - handleClick && handleClick(e, index); + parentOnSelect && parentOnSelect(e, { eventKey }); }; render() { @@ -68,10 +49,10 @@ class Button extends React.Component { color, containerLarge, disabled, + eventKey, expand, href, - index, - isButtonGroup, + keyboardKey, label, loading, large, @@ -84,12 +65,13 @@ class Button extends React.Component { } = this.props; const otherProps = omit({...props}, [ - 'onClick' + 'id', + 'onClick', + 'parentOnSelect', + 'parentKeyDown' ]); - const { focusIndex } = this.context; - - const isButtonGroupIcon = () => ( + const isButtonGroupIcon = isButtonGroup => ( isButtonGroup && children && React.Children.toArray(children).reduce((prev, child) => @@ -100,7 +82,7 @@ class Button extends React.Component { ); const getChildren = () => { - return children + return children && [ loading &&
@@ -149,32 +131,70 @@ class Button extends React.Component { ['none', '28', '36', '40', '52', 28, 36, 40, 52].includes(size) ); - const button = React.createElement( + const getTabIndex = ({ isButtonGroup, focus }) => { + if(!isButtonGroup) { + return 0; + } else if (isButtonGroup && focus) { + return 0; + } else return -1; + }; + + const withContext = () => ( + `md-button-${id}`}> + {id => ( + + {context => { + let contextProps = {}; + + contextProps.id = this.props.id || id; + contextProps.uniqueKey = eventKey || contextProps.id; + contextProps.active = active || (context && context.active === contextProps.uniqueKey); + contextProps.isButtonGroup = (context && context.isButtonGroup) || false; + contextProps.focus = context && context.focus === contextProps.uniqueKey; + contextProps.width = (context && context.width) || null; + contextProps.tabIndex = disabled ? null : getTabIndex(contextProps); + + return createElement(contextProps); + }} + + )} + + ); + + const keyboardNavKey = makeKeyboardKey(keyboardKey || label || children); + + const createElement = cxtProps => React.createElement( tag, { - ref: 'button', + ref: ref => this.button = ref, className: 'md-button' + `${(circle && ` md-button--circle`) || ''}` + - `${(isButtonGroupIcon() && ` md-button--icon-group`) || ''}` + + `${(isButtonGroupIcon(cxtProps.isButtonGroup) && ` md-button--icon-group`) || ''}` + `${(getSize() && ` md-button--${getSize()}`) || ''}` + `${(expand && ` md-button--expand`) || ''}` + `${(color && ` md-button--${getColor()}`) || ''}` + `${(removeStyle && ' md-button--none') || ''}` + - `${(active && !disabled && ` active`) || ''}` + + `${(cxtProps.active && !disabled && ` active`) || ''}` + `${(className && ` ${className}`) || ''}`, - onClick: this.handleClick, - onKeyDown: this.handleKeyDown, - style: style, + id: cxtProps.id, + 'data-md-event-key': cxtProps.uniqueKey, + onClick: e => this.handleClick(e, cxtProps.uniqueKey), + onKeyDown: e => this.handleKeyDown(e, cxtProps.uniqueKey), + style: { + style, + ...cxtProps.width && { width: cxtProps.width } + }, disabled: disabled || loading, alt: ariaLabel || label, href: (tag === 'a' && href) || undefined, type: tag !== 'a' && type || '', + ...keyboardNavKey && { 'data-md-keyboard-key': keyboardNavKey }, + ...cxtProps.focus && { 'aria-current': `${cxtProps.focus}` }, ...ariaLabel ? { 'aria-label': ariaLabel } : { 'aria-labelledby': ariaLabelledBy }, - tabIndex: (typeof index !== 'number' - || index === focusIndex) ? 0 : -1, + tabIndex: cxtProps.tabIndex, ...tag && tag !== 'button' && {role: 'button'}, ...otherProps, }, @@ -187,24 +207,17 @@ class Button extends React.Component {
- {button} + {withContext()}
{label}
: - button + withContext() ); } } -Button.contextTypes = { - focusIndex: PropTypes.number, - focusOnLoad: PropTypes.bool, - handleClick: PropTypes.func, - handleKeyDown: PropTypes.func, -}; - Button.propTypes = { /** @prop Sets active css styling | false */ active: PropTypes.bool, @@ -224,14 +237,16 @@ Button.propTypes = { containerLarge: PropTypes.bool, /** @prop Sets the attribute disabled to Button | false */ disabled: PropTypes.bool, + /** @prop Unique string used for tracking events among ancestors | '' */ + eventKey: PropTypes.string, /** @prop Sets expand css styling to widen the Button | false */ expand: PropTypes.bool, /** @prop Href prop changes element to anchor element | '' */ href: PropTypes.string, - /** @prop This index is used to control focus of Button within a ButtonGroup | null */ - index: PropTypes.number, - /** @prop Determines whether class should be applied to ButtonGroups with Icons as descendants | false */ - isButtonGroup: PropTypes.bool, + /** @prop Sets Button id | null */ + id: PropTypes.string, + /** @prop Unique string used for keyboard navigation | '' */ + keyboardKey: PropTypes.string, /** @prop Text to display inside the button | '' */ label: PropTypes.string, /** @prop Depreciated large css styling, use size instead | false */ @@ -240,6 +255,10 @@ Button.propTypes = { loading: PropTypes.bool, /** @prop Handler to be called when the user taps the button | null */ onClick: PropTypes.func, + // Internal Context Use Only + parentKeyDown: PropTypes.func, + // Internal Context Use Only + parentOnSelect: PropTypes.func, /** @prop Optional prop to remove Button's default style | false */ removeStyle: PropTypes.bool, /** @prop Optional string or number size prop | 36 */ @@ -262,14 +281,17 @@ Button.defaultProps = { color: '', containerLarge: false, disabled: false, + eventKey: '', expand: false, href: '', - index: null, - isButtonGroup: false, + id: '', + keyboardKey: '', label: '', large: false, loading: false, onClick: null, + parentKeyDown: null, + parentOnSelect: null, removeStyle: false, size: 36, style: {}, @@ -277,4 +299,10 @@ Button.defaultProps = { type: 'button', }; -export default Button; +Button.displayName = 'Button'; + +export default mapContextToProps( + SelectableContext, + context => context, + Button +); diff --git a/react/src/lib/Button/tests/__snapshots__/index.spec.js.snap b/react/src/lib/Button/tests/__snapshots__/index.spec.js.snap index 6868eab36a..7c950dc9cd 100644 --- a/react/src/lib/Button/tests/__snapshots__/index.spec.js.snap +++ b/react/src/lib/Button/tests/__snapshots__/index.spec.js.snap @@ -3,31 +3,11 @@ exports[`tests for , + , Symbol(enzyme.__renderer__): Object { "batchedUpdates": [Function], "checkPropTypes": [Function], @@ -40,103 +20,59 @@ ShallowWrapper { Symbol(enzyme.__node__): Object { "instance": null, "key": undefined, - "nodeType": "host", + "nodeType": "function", "props": Object { - "alt": "test", - "aria-label": "test", - "children": Array [ - false, - - test - , - ], - "className": "md-button md-button--36", - "disabled": false, - "href": undefined, - "onClick": [Function], - "onKeyDown": [Function], - "style": Object {}, - "tabIndex": 0, - "type": "button", + "children": [Function], }, - "ref": "button", - "rendered": Array [ - false, - Object { - "instance": null, - "key": "child-1", - "nodeType": "host", - "props": Object { - "children": "test", - "className": "md-button__children", - "style": Object { - "opacity": "1", - }, + "ref": null, + "rendered": [Function], + "type": Object { + "$$typeof": Symbol(react.context), + "_calculateChangedBits": null, + "_context": Object { + "$$typeof": Symbol(react.context), + "Consumer": [Circular], + "Provider": Object { + "$$typeof": Symbol(react.provider), + "_context": [Circular], }, - "ref": null, - "rendered": "test", - "type": "span", + "_calculateChangedBits": null, + "_currentRenderer": null, + "_currentRenderer2": null, + "_currentValue": undefined, + "_currentValue2": undefined, + "_threadCount": 0, }, - ], - "type": "button", + }, }, Symbol(enzyme.__nodes__): Array [ Object { "instance": null, "key": undefined, - "nodeType": "host", + "nodeType": "function", "props": Object { - "alt": "test", - "aria-label": "test", - "children": Array [ - false, - - test - , - ], - "className": "md-button md-button--36", - "disabled": false, - "href": undefined, - "onClick": [Function], - "onKeyDown": [Function], - "style": Object {}, - "tabIndex": 0, - "type": "button", + "children": [Function], }, - "ref": "button", - "rendered": Array [ - false, - Object { - "instance": null, - "key": "child-1", - "nodeType": "host", - "props": Object { - "children": "test", - "className": "md-button__children", - "style": Object { - "opacity": "1", - }, + "ref": null, + "rendered": [Function], + "type": Object { + "$$typeof": Symbol(react.context), + "_calculateChangedBits": null, + "_context": Object { + "$$typeof": Symbol(react.context), + "Consumer": [Circular], + "Provider": Object { + "$$typeof": Symbol(react.provider), + "_context": [Circular], }, - "ref": null, - "rendered": "test", - "type": "span", + "_calculateChangedBits": null, + "_currentRenderer": null, + "_currentRenderer2": null, + "_currentValue": undefined, + "_currentValue2": undefined, + "_threadCount": 0, }, - ], - "type": "button", + }, }, ], Symbol(enzyme.__options__): Object { @@ -165,6 +101,5 @@ ShallowWrapper { Symbol(enzyme.__providerValues__): undefined, }, Symbol(enzyme.__providerValues__): Map {}, - Symbol(enzyme.__childContext__): null, } `; diff --git a/react/src/lib/Button/tests/index.spec.js b/react/src/lib/Button/tests/index.spec.js index deb45586da..177a570289 100644 --- a/react/src/lib/Button/tests/index.spec.js +++ b/react/src/lib/Button/tests/index.spec.js @@ -1,6 +1,8 @@ import React from 'react'; import { shallow, mount } from 'enzyme'; import { Button, Loading } from '@momentum-ui/react'; +import ButtonGroupContext from '../../ButtonGroupContext'; +import SelectableContext from '../../SelectableContext'; describe('tests for @@ -26,25 +28,25 @@ describe('tests for + , Symbol(enzyme.__renderer__): Object { "batchedUpdates": [Function], @@ -53,162 +35,330 @@ ShallowWrapper { Symbol(enzyme.__node__): Object { "instance": null, "key": undefined, - "nodeType": "host", + "nodeType": "function", "props": Object { - "aria-label": "", - "children": Array [ - , - ], - "className": "md-button-group md-button-group--justified", - "role": "group", + > + + 1 + + + +
, + "value": Object { + "parentKeyDown": [Function], + "parentOnSelect": [Function], + }, }, "ref": null, - "rendered": Array [ - Object { - "instance": null, - "key": ".0", - "nodeType": "class", - "props": Object { - "active": false, - "ariaLabel": "test", - "ariaLabelledBy": "", - "children": "1", - "circle": false, - "className": "", - "color": "", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": 0, - "isButtonGroup": true, - "label": "", - "large": false, - "loading": false, - "onClick": null, - "removeStyle": false, - "size": 36, - "style": Object { - "width": "60px", - }, - "tag": "button", - "type": "button", - }, - "ref": null, - "rendered": "1", - "type": [Function], - }, - ], - "type": "div", - }, - Symbol(enzyme.__nodes__): Array [ - Object { + "rendered": Object { "instance": null, "key": undefined, "nodeType": "host", "props": Object { "aria-label": "", - "children": Array [ - , - ], + + 1 + + + , "className": "md-button-group md-button-group--justified", "role": "group", }, - "ref": null, - "rendered": Array [ - Object { + "ref": [Function], + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "function", + "props": Object { + "children": + + 1 + + , + }, + "ref": null, + "rendered": Object { "instance": null, - "key": ".0", - "nodeType": "class", + "key": undefined, + "nodeType": "function", "props": Object { - "active": false, - "ariaLabel": "test", - "ariaLabelledBy": "", - "children": "1", - "circle": false, - "className": "", - "color": "", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": 0, - "isButtonGroup": true, - "label": "", - "large": false, - "loading": false, - "onClick": null, - "removeStyle": false, - "size": 36, - "style": Object { + "children": + 1 + , + "value": Object { + "active": "", + "focus": null, + "isButtonGroup": true, "width": "60px", }, - "tag": "button", - "type": "button", }, "ref": null, - "rendered": "1", - "type": [Function], + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "function", + "props": Object { + "ariaLabel": "test", + "children": "1", + }, + "ref": null, + "rendered": "1", + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, + }, + "type": Object { + "$$typeof": Symbol(react.provider), + "_context": Object { + "$$typeof": Symbol(react.context), + "Consumer": Object { + "$$typeof": Symbol(react.context), + "_calculateChangedBits": null, + "_context": [Circular], + }, + "Provider": [Circular], + "_calculateChangedBits": null, + "_currentRenderer": null, + "_currentRenderer2": null, + "_currentValue": null, + "_currentValue2": null, + "_threadCount": 0, + }, + }, }, - ], + "type": [Function], + }, "type": "div", }, + "type": Object { + "$$typeof": Symbol(react.provider), + "_context": Object { + "$$typeof": Symbol(react.context), + "Consumer": Object { + "$$typeof": Symbol(react.context), + "_calculateChangedBits": null, + "_context": [Circular], + }, + "Provider": [Circular], + "_calculateChangedBits": null, + "_currentRenderer": null, + "_currentRenderer2": null, + "_currentValue": undefined, + "_currentValue2": undefined, + "_threadCount": 0, + }, + }, + }, + Symbol(enzyme.__nodes__): Array [ + Object { + "instance": null, + "key": undefined, + "nodeType": "function", + "props": Object { + "children":
+ + + + 1 + + + +
, + "value": Object { + "parentKeyDown": [Function], + "parentOnSelect": [Function], + }, + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "host", + "props": Object { + "aria-label": "", + "children": + + + 1 + + + , + "className": "md-button-group md-button-group--justified", + "role": "group", + }, + "ref": [Function], + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "function", + "props": Object { + "children": + + 1 + + , + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "function", + "props": Object { + "children": + 1 + , + "value": Object { + "active": "", + "focus": null, + "isButtonGroup": true, + "width": "60px", + }, + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "function", + "props": Object { + "ariaLabel": "test", + "children": "1", + }, + "ref": null, + "rendered": "1", + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, + }, + "type": Object { + "$$typeof": Symbol(react.provider), + "_context": Object { + "$$typeof": Symbol(react.context), + "Consumer": Object { + "$$typeof": Symbol(react.context), + "_calculateChangedBits": null, + "_context": [Circular], + }, + "Provider": [Circular], + "_calculateChangedBits": null, + "_currentRenderer": null, + "_currentRenderer2": null, + "_currentValue": null, + "_currentValue2": null, + "_threadCount": 0, + }, + }, + }, + "type": [Function], + }, + "type": "div", + }, + "type": Object { + "$$typeof": Symbol(react.provider), + "_context": Object { + "$$typeof": Symbol(react.context), + "Consumer": Object { + "$$typeof": Symbol(react.context), + "_calculateChangedBits": null, + "_context": [Circular], + }, + "Provider": [Circular], + "_calculateChangedBits": null, + "_currentRenderer": null, + "_currentRenderer2": null, + "_currentValue": undefined, + "_currentValue2": undefined, + "_threadCount": 0, + }, + }, + }, ], Symbol(enzyme.__options__): Object { "adapter": ReactSixteenAdapter { @@ -236,11 +386,6 @@ ShallowWrapper { Symbol(enzyme.__providerValues__): undefined, }, Symbol(enzyme.__providerValues__): Map {}, - Symbol(enzyme.__childContext__): Object { - "focusIndex": 0, - "focusOnLoad": false, - "handleClick": [Function], - "handleKeyDown": [Function], - }, + Symbol(enzyme.__childContext__): null, } `; diff --git a/react/src/lib/ButtonGroup/tests/index.spec.js b/react/src/lib/ButtonGroup/tests/index.spec.js index deef8cb07c..bf058b7564 100644 --- a/react/src/lib/ButtonGroup/tests/index.spec.js +++ b/react/src/lib/ButtonGroup/tests/index.spec.js @@ -85,12 +85,13 @@ describe('tests for ', () => { expect(document.activeElement.id).toEqual('one'); }); - it('when activeIndex prop is passed, the button should be selected', () => { + it('when active prop is passed, the button should be selected', () => { const container = mount( - + - ); + + ); expect(container.find('button').at(1).hasClass('active')).toEqual(true); }); diff --git a/react/src/lib/ButtonGroupContext/index.js b/react/src/lib/ButtonGroupContext/index.js new file mode 100644 index 0000000000..a446c88313 --- /dev/null +++ b/react/src/lib/ButtonGroupContext/index.js @@ -0,0 +1,5 @@ +import React from 'react'; + +const ButtonGroupContext = React.createContext(null); + +export default ButtonGroupContext; diff --git a/react/src/lib/CallControl/tests/__snapshots__/index.spec.js.snap b/react/src/lib/CallControl/tests/__snapshots__/index.spec.js.snap index 8784bfd006..340b2eb644 100644 --- a/react/src/lib/CallControl/tests/__snapshots__/index.spec.js.snap +++ b/react/src/lib/CallControl/tests/__snapshots__/index.spec.js.snap @@ -26,11 +26,9 @@ ShallowWrapper { Symbol(enzyme.__node__): Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "test", - "ariaLabelledBy": "", "children": ', () => { }); it('should render one Call Control button', () => { - const container = shallow(); + const container = mount(); expect(container.find('Button').length).toEqual(1); }); diff --git a/react/src/lib/CollapseButton/tests/__snapshots__/index.spec.js.snap b/react/src/lib/CollapseButton/tests/__snapshots__/index.spec.js.snap index 129f0b7c38..9e47270533 100644 --- a/react/src/lib/CollapseButton/tests/__snapshots__/index.spec.js.snap +++ b/react/src/lib/CollapseButton/tests/__snapshots__/index.spec.js.snap @@ -21,11 +21,9 @@ ShallowWrapper { Symbol(enzyme.__node__): Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "expand", - "ariaLabelledBy": "", "children": , - "circle": false, "className": "md-collapse-button md-collapse-button--left", - "color": "", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": [Function], - "removeStyle": false, - "size": 36, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -88,17 +70,20 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, Symbol(enzyme.__nodes__): Array [ Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "ariaLabel": "expand", - "ariaLabelledBy": "", "children": , - "circle": false, "className": "md-collapse-button md-collapse-button--left", - "color": "", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": [Function], - "removeStyle": false, - "size": 36, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -161,7 +130,12 @@ ShallowWrapper { "rendered": null, "type": [Function], }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, ], Symbol(enzyme.__options__): Object { diff --git a/react/src/lib/CollapseButton/tests/index.spec.js b/react/src/lib/CollapseButton/tests/index.spec.js index 36406aaf01..2ab6a9d498 100644 --- a/react/src/lib/CollapseButton/tests/index.spec.js +++ b/react/src/lib/CollapseButton/tests/index.spec.js @@ -18,13 +18,13 @@ describe('tests for ', () => { }); it('when collapse is true it should display right icon and label', () => { - const container = shallow(); + const container = mount(); expect(container.find('Icon').props().name).toEqual('panel-control-right_12'); expect(container.find('Button').props().ariaLabel).toEqual('expand'); }); it('when collapse is false it should display right icon and label', () => { - const container = shallow(); + const container = mount(); expect(container.find('Icon').props().name).toEqual('panel-control-left_12'); expect(container.find('Button').props().ariaLabel).toEqual('collapse'); }); diff --git a/react/src/lib/ContentItem/examples/Default.js b/react/src/lib/ContentItem/examples/Default.js index b5b46772fb..9619830325 100644 --- a/react/src/lib/ContentItem/examples/Default.js +++ b/react/src/lib/ContentItem/examples/Default.js @@ -54,18 +54,6 @@ export default class ChatContentItem extends React.PureComponent { type="chat" /> - -
- -
); } diff --git a/react/src/lib/ContentItem/examples/File.js b/react/src/lib/ContentItem/examples/File.js index 0a00a19b7d..4700428e74 100644 --- a/react/src/lib/ContentItem/examples/File.js +++ b/react/src/lib/ContentItem/examples/File.js @@ -62,19 +62,6 @@ export default class FileContentItem extends React.PureComponent { type="file" /> - -
- -
); } diff --git a/react/src/lib/ContentItem/examples/Gif.js b/react/src/lib/ContentItem/examples/Gif.js new file mode 100644 index 0000000000..24f0ace810 --- /dev/null +++ b/react/src/lib/ContentItem/examples/Gif.js @@ -0,0 +1,69 @@ +import React from 'react'; +import { Button, ContentItem, Icon } from '@momentum-ui/react'; + +export default class GifContentItem extends React.PureComponent { + render() { + const actionNode = ( +
+ + + + + +
+ ); + + const handleClick = () => { + alert('Image onClick'); + }; + + return ( +
+
+ +
+
+ +
+
+ ); + } +} diff --git a/react/src/lib/ContentItem/examples/KitchenSink.js b/react/src/lib/ContentItem/examples/KitchenSink.js index 65a03a70f0..a46669ab69 100644 --- a/react/src/lib/ContentItem/examples/KitchenSink.js +++ b/react/src/lib/ContentItem/examples/KitchenSink.js @@ -10,6 +10,7 @@ import { } from './index'; export default class ContentItemKitchenSink extends React.Component { + // GIF example not included due to snapshot render() { return ( diff --git a/react/src/lib/ContentItem/examples/index.js b/react/src/lib/ContentItem/examples/index.js index 69458a0d9d..47f7e73819 100644 --- a/react/src/lib/ContentItem/examples/index.js +++ b/react/src/lib/ContentItem/examples/index.js @@ -2,6 +2,7 @@ export { default as ContentItemAspect } from './Aspect'; export { default as ContentItemDefault } from './Default'; export { default as ContentItemFailed } from './Failed'; export { default as ContentItemFile } from './File'; +export { default as ContentItemGif } from './Gif'; export { default as ContentItemIcon } from './Icon'; export { default as ContentItemKitchenSink } from './KitchenSink'; export { default as ContentItemSize } from './Size'; diff --git a/react/src/lib/DatePicker/DatePickerDay/tests/__snapshots__/index.spec.js.snap b/react/src/lib/DatePicker/DatePickerDay/tests/__snapshots__/index.spec.js.snap index cf27845f39..5e81536da5 100644 --- a/react/src/lib/DatePicker/DatePickerDay/tests/__snapshots__/index.spec.js.snap +++ b/react/src/lib/DatePicker/DatePickerDay/tests/__snapshots__/index.spec.js.snap @@ -20,12 +20,10 @@ ShallowWrapper { Symbol(enzyme.__node__): Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "aria-selected": false, "ariaLabel": "Saturday, April 21st 2018", - "ariaLabelledBy": "", "children":
@@ -33,23 +31,10 @@ ShallowWrapper {
, "circle": true, "className": "md-datepicker__day", - "color": "", - "containerLarge": false, "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": [Function], - "removeStyle": false, "size": 28, - "style": Object {}, "tabIndex": -1, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -64,18 +49,21 @@ ShallowWrapper { "rendered": 21, "type": "div", }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, Symbol(enzyme.__nodes__): Array [ Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { - "active": false, "aria-selected": false, "ariaLabel": "Saturday, April 21st 2018", - "ariaLabelledBy": "", "children":
@@ -83,23 +71,10 @@ ShallowWrapper {
, "circle": true, "className": "md-datepicker__day", - "color": "", - "containerLarge": false, "disabled": false, - "expand": false, - "href": "", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "onClick": [Function], - "removeStyle": false, "size": 28, - "style": Object {}, "tabIndex": -1, - "tag": "button", - "type": "button", }, "ref": null, "rendered": Object { @@ -114,7 +89,12 @@ ShallowWrapper { "rendered": 21, "type": "div", }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, ], Symbol(enzyme.__options__): Object { diff --git a/react/src/lib/Select/tests/__snapshots__/index.spec.js.snap b/react/src/lib/Select/tests/__snapshots__/index.spec.js.snap index a0716e248e..921b045ec4 100644 --- a/react/src/lib/Select/tests/__snapshots__/index.spec.js.snap +++ b/react/src/lib/Select/tests/__snapshots__/index.spec.js.snap @@ -31,31 +31,13 @@ ShallowWrapper { "children":
- +
, "value": false, }, @@ -91,31 +73,13 @@ ShallowWrapper { "nodeType": "host", "props": Object { "children": Array [ - , + , false, ], "className": "md-input-container md-select", @@ -150,11 +114,10 @@ ShallowWrapper { Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { "active": false, "aria-haspopup": "listbox", - "ariaLabel": "", "ariaLabelledBy": "md-select-1__label", "children":
, - "circle": false, - "className": "", - "color": "", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", "id": "md-select-1", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "name": "md-select-1", "onClick": [Function], - "removeStyle": false, - "size": 36, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": [Function], "rendered": Object { @@ -260,7 +206,12 @@ ShallowWrapper { ], "type": "div", }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, false, ], @@ -294,31 +245,13 @@ ShallowWrapper { "children":
- +
, "value": false, }, @@ -354,31 +287,13 @@ ShallowWrapper { "nodeType": "host", "props": Object { "children": Array [ - , + , false, ], "className": "md-input-container md-select", @@ -413,11 +328,10 @@ ShallowWrapper { Object { "instance": null, "key": undefined, - "nodeType": "class", + "nodeType": "function", "props": Object { "active": false, "aria-haspopup": "listbox", - "ariaLabel": "", "ariaLabelledBy": "md-select-1__label", "children":
, - "circle": false, - "className": "", - "color": "", - "containerLarge": false, - "disabled": false, - "expand": false, - "href": "", "id": "md-select-1", - "index": null, - "isButtonGroup": false, - "label": "", - "large": false, - "loading": false, "name": "md-select-1", "onClick": [Function], - "removeStyle": false, - "size": 36, - "style": Object {}, - "tag": "button", - "type": "button", }, "ref": [Function], "rendered": Object { @@ -523,7 +420,12 @@ ShallowWrapper { ], "type": "div", }, - "type": [Function], + "type": Object { + "$$typeof": Symbol(react.forward_ref), + "defaultProps": undefined, + "propTypes": undefined, + "render": [Function], + }, }, false, ], diff --git a/react/src/lib/SelectableContext/index.js b/react/src/lib/SelectableContext/index.js index 5e9bc2c9f9..3ea0273cba 100644 --- a/react/src/lib/SelectableContext/index.js +++ b/react/src/lib/SelectableContext/index.js @@ -8,7 +8,7 @@ export const makeEventKey = eventKey => { }; export const makeKeyboardKey = keyboardKey => { - return kebabCase(String(keyboardKey)); + return typeof keyboardKey === 'string' && kebabCase(String(keyboardKey)); }; export default SelectableContext; diff --git a/react/src/lib/TimePicker/examples/24Hour.js b/react/src/lib/TimePicker/examples/24Hour.js index 41e9590629..0ac11c8f9d 100644 --- a/react/src/lib/TimePicker/examples/24Hour.js +++ b/react/src/lib/TimePicker/examples/24Hour.js @@ -5,7 +5,7 @@ export default class TimePicker24Hr extends React.PureComponent { return (
diff --git a/react/src/lib/TimePicker/examples/30MinuteStep.js b/react/src/lib/TimePicker/examples/30MinuteStep.js index d4844398b0..6266b1ceed 100644 --- a/react/src/lib/TimePicker/examples/30MinuteStep.js +++ b/react/src/lib/TimePicker/examples/30MinuteStep.js @@ -5,7 +5,7 @@ export default class TimePicker30MinStep extends React.PureComponent { render() { return (
- +
); } diff --git a/react/src/lib/TimePicker/examples/Default.js b/react/src/lib/TimePicker/examples/Default.js index a0b0717fc0..0ac91db6be 100644 --- a/react/src/lib/TimePicker/examples/Default.js +++ b/react/src/lib/TimePicker/examples/Default.js @@ -5,7 +5,7 @@ export default class TimePickerDefault extends React.PureComponent { return (