@dhis2-ui/button 9.5.0-alpha.1 → 9.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/build/cjs/button/__tests__/Button.test.js +0 -31
- package/build/cjs/button/button.js +0 -8
- package/build/cjs/button/features/can_be_blurred/index.js +4 -4
- package/build/cjs/button/features/can_be_clicked/index.js +4 -4
- package/build/cjs/button/features/can_be_focused/index.js +4 -4
- package/build/cjs/button-strip/features/accepts_children/index.js +3 -3
- package/build/cjs/dropdown-button/__tests__/dropdown-button.test.js +65 -5
- package/build/cjs/dropdown-button/dropdown-button.js +21 -1
- package/build/cjs/dropdown-button/features/accepts_children/index.js +3 -3
- package/build/cjs/dropdown-button/features/accepts_component/index.js +3 -3
- package/build/cjs/dropdown-button/features/accepts_icon/index.js +3 -3
- package/build/cjs/dropdown-button/features/accepts_initial_focus/index.js +3 -3
- package/build/cjs/dropdown-button/features/button_is_clickable/index.js +3 -5
- package/build/cjs/dropdown-button/features/can_be_disabled/index.js +3 -8
- package/build/cjs/dropdown-button/features/common/index.js +2 -2
- package/build/cjs/dropdown-button/features/opens_a_dropdown/index.js +6 -8
- package/build/cjs/split-button/features/accepts_children/index.js +3 -3
- package/build/cjs/split-button/features/accepts_icon/index.js +5 -5
- package/build/cjs/split-button/features/accepts_initial_focus/index.js +3 -3
- package/build/cjs/split-button/features/arrow_opens_menu/index.js +9 -11
- package/build/cjs/split-button/features/button_is_clickable/index.js +3 -5
- package/build/cjs/split-button/features/can_be_disabled/index.js +6 -6
- package/build/cjs/split-button/features/common/index.js +3 -3
- package/build/cjs/split-button/split-button.js +4 -30
- package/build/es/button/__tests__/Button.test.js +0 -31
- package/build/es/button/button.js +0 -8
- package/build/es/button/features/can_be_blurred/index.js +1 -1
- package/build/es/button/features/can_be_clicked/index.js +1 -1
- package/build/es/button/features/can_be_focused/index.js +1 -1
- package/build/es/button-strip/features/accepts_children/index.js +1 -1
- package/build/es/dropdown-button/__tests__/dropdown-button.test.js +48 -0
- package/build/es/dropdown-button/dropdown-button.js +21 -1
- package/build/es/dropdown-button/features/accepts_children/index.js +1 -1
- package/build/es/dropdown-button/features/accepts_component/index.js +1 -1
- package/build/es/dropdown-button/features/accepts_icon/index.js +1 -1
- package/build/es/dropdown-button/features/accepts_initial_focus/index.js +1 -1
- package/build/es/dropdown-button/features/button_is_clickable/index.js +1 -2
- package/build/es/dropdown-button/features/can_be_disabled/index.js +1 -6
- package/build/es/dropdown-button/features/common/index.js +1 -1
- package/build/es/dropdown-button/features/opens_a_dropdown/index.js +1 -2
- package/build/es/split-button/features/accepts_children/index.js +1 -1
- package/build/es/split-button/features/accepts_icon/index.js +3 -3
- package/build/es/split-button/features/accepts_initial_focus/index.js +1 -1
- package/build/es/split-button/features/arrow_opens_menu/index.js +1 -2
- package/build/es/split-button/features/button_is_clickable/index.js +1 -2
- package/build/es/split-button/features/can_be_disabled/index.js +1 -1
- package/build/es/split-button/features/common/index.js +1 -1
- package/build/es/split-button/split-button.js +4 -29
- package/package.json +6 -6
- package/types/index.d.ts +4 -1
- package/build/cjs/locales/en/translations.json +0 -3
- package/build/cjs/locales/index.js +0 -27
- package/build/cjs/split-button/split-button.test.js +0 -99
- package/build/es/locales/en/translations.json +0 -3
- package/build/es/locales/index.js +0 -13
- package/build/es/split-button/split-button.test.js +0 -77
@@ -11,37 +11,6 @@ var _button = require("../button.js");
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
12
12
|
|
13
13
|
describe('<Button>', () => {
|
14
|
-
let consoleSpy;
|
15
|
-
beforeEach(() => {
|
16
|
-
consoleSpy = jest.spyOn(console, 'debug').mockImplementation();
|
17
|
-
});
|
18
|
-
afterEach(() => {
|
19
|
-
consoleSpy.mockRestore();
|
20
|
-
});
|
21
|
-
describe('warning for missing aria-label and title', () => {
|
22
|
-
it('No warning if children exist but aria-label and title is missing', () => {
|
23
|
-
(0, _react.render)( /*#__PURE__*/_react2.default.createElement(_button.Button, null, "Children content"));
|
24
|
-
expect(consoleSpy).not.toHaveBeenCalled();
|
25
|
-
});
|
26
|
-
it('does not warn if aria-label and title is present', () => {
|
27
|
-
(0, _react.render)( /*#__PURE__*/_react2.default.createElement(_button.Button, {
|
28
|
-
"aria-label": "Test",
|
29
|
-
title: "Test"
|
30
|
-
}, "Children content"));
|
31
|
-
expect(consoleSpy).not.toHaveBeenCalled();
|
32
|
-
});
|
33
|
-
it('warns if no children are present with no arial-label and title', () => {
|
34
|
-
(0, _react.render)( /*#__PURE__*/_react2.default.createElement(_button.Button, null));
|
35
|
-
expect(consoleSpy).toHaveBeenCalledWith('Button component has no children but is missing title and ariaLabel attribute.');
|
36
|
-
});
|
37
|
-
it('No warning if there are no children but arial label and title', () => {
|
38
|
-
(0, _react.render)( /*#__PURE__*/_react2.default.createElement(_button.Button, {
|
39
|
-
"aria-label": "Test",
|
40
|
-
title: "Test"
|
41
|
-
}));
|
42
|
-
expect(consoleSpy).not.toHaveBeenCalled();
|
43
|
-
});
|
44
|
-
});
|
45
14
|
it('renders a default data-test attribute', () => {
|
46
15
|
const dataTest = 'dhis2-uicore-button';
|
47
16
|
const wrapper = (0, _enzyme.mount)( /*#__PURE__*/_react2.default.createElement(_button.Button, {
|
@@ -58,14 +58,6 @@ const Button = _ref => {
|
|
58
58
|
ref.current.focus();
|
59
59
|
}
|
60
60
|
}, [initialFocus, ref.current]);
|
61
|
-
const {
|
62
|
-
'aria-label': ariaLabel,
|
63
|
-
title
|
64
|
-
} = otherProps;
|
65
|
-
|
66
|
-
if (!children && !title && !ariaLabel) {
|
67
|
-
console.debug('Button component has no children but is missing title and ariaLabel attribute.');
|
68
|
-
}
|
69
61
|
|
70
62
|
const handleClick = event => onClick && onClick({
|
71
63
|
value,
|
@@ -1,15 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('an Button with initialFocus and onBlur handler is rendered', () => {
|
6
6
|
cy.visitStory('Button', 'With initialFocus and onBlur');
|
7
7
|
cy.focused().should('exist');
|
8
8
|
});
|
9
|
-
(0,
|
9
|
+
(0, _cypressCucumberPreprocessor.When)('the Button is blurred', () => {
|
10
10
|
cy.get('[data-test="dhis2-uicore-button"]').blur();
|
11
11
|
});
|
12
|
-
(0,
|
12
|
+
(0, _cypressCucumberPreprocessor.Then)('the onBlur handler is called', () => {
|
13
13
|
cy.window().should(win => {
|
14
14
|
expect(win.onBlur).to.be.calledWith({
|
15
15
|
value: 'default',
|
@@ -1,14 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a Button with onClick handler is rendered', () => {
|
6
6
|
cy.visitStory('Button', 'With onClick');
|
7
7
|
});
|
8
|
-
(0,
|
8
|
+
(0, _cypressCucumberPreprocessor.When)('the Button is clicked', () => {
|
9
9
|
cy.get('[data-test="dhis2-uicore-button"]').click();
|
10
10
|
});
|
11
|
-
(0,
|
11
|
+
(0, _cypressCucumberPreprocessor.Then)('the onClick handler is called', () => {
|
12
12
|
cy.window().should(win => {
|
13
13
|
expect(win.onClick).to.be.calledWith({
|
14
14
|
name: 'Button',
|
@@ -1,14 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a Button with onFocus handler is rendered', () => {
|
6
6
|
cy.visitStory('Button', 'With onFocus');
|
7
7
|
});
|
8
|
-
(0,
|
8
|
+
(0, _cypressCucumberPreprocessor.When)('the Button is focused', () => {
|
9
9
|
cy.get('[data-test="dhis2-uicore-button"]').focus();
|
10
10
|
});
|
11
|
-
(0,
|
11
|
+
(0, _cypressCucumberPreprocessor.Then)('the onFocus handler is called', () => {
|
12
12
|
cy.window().should(win => {
|
13
13
|
expect(win.onFocus).to.be.calledWith({
|
14
14
|
value: 'default',
|
@@ -1,11 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a ButtonStrip with children is rendered', () => {
|
6
6
|
cy.visitStory('ButtonStrip', 'With children');
|
7
7
|
cy.get('[data-test="dhis2-uicore-buttonstrip"]').should('be.visible');
|
8
8
|
});
|
9
|
-
(0,
|
9
|
+
(0, _cypressCucumberPreprocessor.Then)('the children are visible', () => {
|
10
10
|
cy.contains('I am a child').should('be.visible');
|
11
11
|
});
|
@@ -4,12 +4,16 @@ var _layer = require("@dhis2-ui/layer");
|
|
4
4
|
|
5
5
|
var _popper = require("@dhis2-ui/popper");
|
6
6
|
|
7
|
+
var _react = require("@testing-library/react");
|
8
|
+
|
7
9
|
var _enzyme = require("enzyme");
|
8
10
|
|
9
|
-
var
|
11
|
+
var _react2 = _interopRequireDefault(require("react"));
|
10
12
|
|
11
13
|
var _testUtils = require("react-dom/test-utils");
|
12
14
|
|
15
|
+
var _modal = require("../../../../modal/src/modal/modal.js");
|
16
|
+
|
13
17
|
var _index = require("../../index.js");
|
14
18
|
|
15
19
|
var _dropdownButton = require("../dropdown-button.js");
|
@@ -21,10 +25,10 @@ describe('<DropdownButton>', () => {
|
|
21
25
|
describe('open state', () => {
|
22
26
|
const onClick = jest.fn();
|
23
27
|
|
24
|
-
const Component = /*#__PURE__*/
|
28
|
+
const Component = /*#__PURE__*/_react2.default.createElement(_dropdownButton.DropdownButton, {
|
25
29
|
onClick: onClick,
|
26
30
|
open: true,
|
27
|
-
component: /*#__PURE__*/
|
31
|
+
component: /*#__PURE__*/_react2.default.createElement("span", null, "test")
|
28
32
|
});
|
29
33
|
|
30
34
|
it('shows the Popper when open is true', async () => {
|
@@ -47,13 +51,69 @@ describe('<DropdownButton>', () => {
|
|
47
51
|
open: false
|
48
52
|
}));
|
49
53
|
});
|
54
|
+
it('closes dropdown when escape key is pressed', async () => {
|
55
|
+
const componentText = 'Dropdown Content';
|
56
|
+
const {
|
57
|
+
getByTestId,
|
58
|
+
queryByText
|
59
|
+
} = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_dropdownButton.DropdownButton, {
|
60
|
+
component: componentText
|
61
|
+
}));
|
62
|
+
const toggleButton = getByTestId('dhis2-uicore-dropdownbutton-toggle');
|
63
|
+
|
64
|
+
_react.fireEvent.click(toggleButton);
|
65
|
+
|
66
|
+
await (0, _react.waitFor)(() => {
|
67
|
+
expect(queryByText(componentText)).toBeInTheDocument();
|
68
|
+
});
|
69
|
+
|
70
|
+
_react.fireEvent.keyDown(document, {
|
71
|
+
key: 'Escape'
|
72
|
+
});
|
73
|
+
|
74
|
+
await (0, _react.waitFor)(() => {
|
75
|
+
expect(queryByText(componentText)).not.toBeInTheDocument();
|
76
|
+
});
|
77
|
+
});
|
78
|
+
test('modal remains open when dropdown button is closed on escape click', async () => {
|
79
|
+
const dropdownButtonText = 'Dropdown Content';
|
80
|
+
const headingText = 'Heading Text';
|
81
|
+
|
82
|
+
const modalContent = /*#__PURE__*/_react2.default.createElement("div", null, /*#__PURE__*/_react2.default.createElement("h1", null, headingText), /*#__PURE__*/_react2.default.createElement(_dropdownButton.DropdownButton, {
|
83
|
+
component: dropdownButtonText
|
84
|
+
}));
|
85
|
+
|
86
|
+
const {
|
87
|
+
getByTestId,
|
88
|
+
queryByText
|
89
|
+
} = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_modal.Modal, {
|
90
|
+
hide: false,
|
91
|
+
onClose: () => {}
|
92
|
+
}, modalContent));
|
93
|
+
const toggleButton = getByTestId('dhis2-uicore-dropdownbutton-toggle');
|
94
|
+
|
95
|
+
_react.fireEvent.click(toggleButton);
|
96
|
+
|
97
|
+
await (0, _react.waitFor)(() => {
|
98
|
+
expect(queryByText(dropdownButtonText)).toBeInTheDocument();
|
99
|
+
});
|
100
|
+
|
101
|
+
_react.fireEvent.keyDown(document, {
|
102
|
+
key: 'Escape'
|
103
|
+
});
|
104
|
+
|
105
|
+
await (0, _react.waitFor)(() => {
|
106
|
+
expect(queryByText(dropdownButtonText)).not.toBeInTheDocument();
|
107
|
+
expect(queryByText(headingText)).toBeInTheDocument();
|
108
|
+
});
|
109
|
+
});
|
50
110
|
});
|
51
111
|
describe('closed state', () => {
|
52
112
|
const onClick = jest.fn();
|
53
|
-
const wrapper = (0, _enzyme.mount)( /*#__PURE__*/
|
113
|
+
const wrapper = (0, _enzyme.mount)( /*#__PURE__*/_react2.default.createElement(_dropdownButton.DropdownButton, {
|
54
114
|
onClick: onClick,
|
55
115
|
open: false,
|
56
|
-
component: /*#__PURE__*/
|
116
|
+
component: /*#__PURE__*/_react2.default.createElement("span", null, "test")
|
57
117
|
}));
|
58
118
|
it('it does not show the Popper when open is false', () => {
|
59
119
|
const popper = wrapper.find(_popper.Popper);
|
@@ -86,6 +86,17 @@ class DropdownButton extends _react.Component {
|
|
86
86
|
|
87
87
|
_defineProperty(this, "anchorRef", /*#__PURE__*/_react.default.createRef());
|
88
88
|
|
89
|
+
_defineProperty(this, "handleKeyDown", event => {
|
90
|
+
event.preventDefault();
|
91
|
+
|
92
|
+
if (event.key === 'Escape' && this.state.open) {
|
93
|
+
event.stopPropagation();
|
94
|
+
this.setState({
|
95
|
+
open: false
|
96
|
+
});
|
97
|
+
}
|
98
|
+
});
|
99
|
+
|
89
100
|
_defineProperty(this, "onClickHandler", (_ref3, event) => {
|
90
101
|
let {
|
91
102
|
name,
|
@@ -114,6 +125,14 @@ class DropdownButton extends _react.Component {
|
|
114
125
|
});
|
115
126
|
}
|
116
127
|
|
128
|
+
componentDidMount() {
|
129
|
+
document.addEventListener('keydown', this.handleKeyDown);
|
130
|
+
}
|
131
|
+
|
132
|
+
componentWillUnmount() {
|
133
|
+
document.removeEventListener('keydown', this.handleKeyDown);
|
134
|
+
}
|
135
|
+
|
117
136
|
render() {
|
118
137
|
const {
|
119
138
|
component,
|
@@ -153,7 +172,8 @@ class DropdownButton extends _react.Component {
|
|
153
172
|
value: value,
|
154
173
|
tabIndex: tabIndex,
|
155
174
|
type: type,
|
156
|
-
initialFocus: initialFocus
|
175
|
+
initialFocus: initialFocus,
|
176
|
+
"data-test": "dhis2-uicore-dropdownbutton-toggle"
|
157
177
|
}, children, /*#__PURE__*/_react.default.createElement(ArrowIconComponent, {
|
158
178
|
className: "jsx-3163060161" + " " + (arrow.className || "")
|
159
179
|
})), open && /*#__PURE__*/_react.default.createElement(_layer.Layer, {
|
@@ -1,11 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a DropdownButton with children is rendered', () => {
|
6
6
|
cy.visitStory('DropdownButton', 'With children');
|
7
7
|
cy.get('[data-test="dhis2-uicore-dropdownbutton"]').should('be.visible');
|
8
8
|
});
|
9
|
-
(0,
|
9
|
+
(0, _cypressCucumberPreprocessor.Then)('the children are visible', () => {
|
10
10
|
cy.contains('I am a child').should('be.visible');
|
11
11
|
});
|
@@ -1,13 +1,13 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a DropdownButton with a component prop and opened dropdown is rendered', () => {
|
6
6
|
cy.visitStory('DropdownButton', 'With component');
|
7
7
|
cy.get('[data-test="dhis2-uicore-dropdownbutton"]').should('be.visible');
|
8
8
|
cy.get('[data-test="dhis2-uicore-dropdownbutton"]').click();
|
9
9
|
cy.get('[data-test="dhis2-uicore-dropdownbutton-popper"]').should('exist');
|
10
10
|
});
|
11
|
-
(0,
|
11
|
+
(0, _cypressCucumberPreprocessor.Then)('the component is visible', () => {
|
12
12
|
cy.contains('I am a component').should('be.visible');
|
13
13
|
});
|
@@ -1,11 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a DropdownButton with an icon prop is rendered', () => {
|
6
6
|
cy.visitStory('DropdownButton', 'With icon');
|
7
7
|
cy.get('[data-test="dhis2-uicore-dropdownbutton"]').should('be.visible');
|
8
8
|
});
|
9
|
-
(0,
|
9
|
+
(0, _cypressCucumberPreprocessor.Then)('the icon is visible', () => {
|
10
10
|
cy.contains('Icon').should('be.visible');
|
11
11
|
});
|
@@ -1,10 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a DropdownButton with initialFocus is rendered', () => {
|
6
6
|
cy.visitStory('DropdownButton', 'With initialFocus');
|
7
7
|
});
|
8
|
-
(0,
|
8
|
+
(0, _cypressCucumberPreprocessor.Then)('the DropdownButton is focused', () => {
|
9
9
|
cy.focused().parent('[data-test="dhis2-uicore-dropdownbutton"]').should('exist');
|
10
10
|
});
|
@@ -1,13 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
require("
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
(0, _steps.Given)('a DropdownButton with onClick handler is rendered', () => {
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a DropdownButton with onClick handler is rendered', () => {
|
8
6
|
cy.visitStory('DropdownButton', 'With onClick');
|
9
7
|
});
|
10
|
-
(0,
|
8
|
+
(0, _cypressCucumberPreprocessor.Then)('the onClick handler is called', () => {
|
11
9
|
cy.window().should(win => {
|
12
10
|
expect(win.onClick).to.be.calledWith({
|
13
11
|
name: 'Button',
|
@@ -1,16 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a disabled DropdownButton with onClick handler is rendered', () => {
|
6
6
|
cy.visitStory('DropdownButton', 'Disabled with onClick');
|
7
7
|
});
|
8
|
-
(0,
|
9
|
-
cy.get('[data-test="dhis2-uicore-dropdownbutton"] button').click({
|
10
|
-
force: true
|
11
|
-
});
|
12
|
-
});
|
13
|
-
(0, _steps.Then)('the onClick handler is not called', () => {
|
8
|
+
(0, _cypressCucumberPreprocessor.Then)('the onClick handler is not called', () => {
|
14
9
|
cy.window().should(win => {
|
15
10
|
expect(win.onClick).not.to.be.called;
|
16
11
|
});
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.When)('the DropdownButton is clicked', () => {
|
6
6
|
cy.get('[data-test="dhis2-uicore-dropdownbutton"]').click();
|
7
7
|
});
|
@@ -1,23 +1,21 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
require("
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
(0, _steps.Given)('a default DropdownButton is rendered', () => {
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a default DropdownButton is rendered', () => {
|
8
6
|
cy.visitStory('DropdownButton', 'Default');
|
9
7
|
});
|
10
|
-
(0,
|
8
|
+
(0, _cypressCucumberPreprocessor.Given)('a DropdownButton with opened dropdown is rendered', () => {
|
11
9
|
cy.visitStory('DropdownButton', 'Default');
|
12
10
|
cy.get('[data-test="dhis2-uicore-dropdownbutton"]').click();
|
13
11
|
cy.get('[data-test="dhis2-uicore-dropdownbutton-popper"]').should('exist');
|
14
12
|
});
|
15
|
-
(0,
|
13
|
+
(0, _cypressCucumberPreprocessor.When)('the user clicks the backdrop Layer', () => {
|
16
14
|
cy.get('[data-test="dhis2-uicore-layer"]').click();
|
17
15
|
});
|
18
|
-
(0,
|
16
|
+
(0, _cypressCucumberPreprocessor.Then)('the dropdown is not rendered', () => {
|
19
17
|
cy.get('[data-test="dhis2-uicore-dropdownbutton-popper"]').should('not.exist');
|
20
18
|
});
|
21
|
-
(0,
|
19
|
+
(0, _cypressCucumberPreprocessor.Then)('the dropdown is rendered', () => {
|
22
20
|
cy.get('[data-test="dhis2-uicore-dropdownbutton-popper"]').should('exist');
|
23
21
|
});
|
@@ -1,11 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a SplitButton with children is rendered', () => {
|
6
6
|
cy.visitStory('SplitButton', 'With children');
|
7
7
|
cy.get('[data-test="dhis2-uicore-splitbutton"]').should('be.visible');
|
8
8
|
});
|
9
|
-
(0,
|
9
|
+
(0, _cypressCucumberPreprocessor.Then)('the children are visible', () => {
|
10
10
|
cy.get('[data-test="dhis2-uicore-splitbutton-button"]').contains('I am a child').should('be.visible');
|
11
11
|
});
|
@@ -1,12 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a SplitButton with an icon is rendered', () => {
|
6
6
|
cy.visitStory('SplitButton', 'With icon');
|
7
7
|
cy.get('[data-test="dhis2-uicore-splitbutton"]').should('be.visible');
|
8
8
|
});
|
9
|
-
(0,
|
10
|
-
cy.get('[data-test="dhis2-uicore-splitbutton-button"]
|
11
|
-
cy.get('[data-test="dhis2-uicore-splitbutton-toggle"]
|
9
|
+
(0, _cypressCucumberPreprocessor.Then)('the icon is visible on the left button only', () => {
|
10
|
+
cy.get('[data-test="dhis2-uicore-splitbutton-button"] :contains("Icon")').should('be.visible');
|
11
|
+
cy.get('[data-test="dhis2-uicore-splitbutton-toggle"] :contains("Icon")').should('not.exist');
|
12
12
|
});
|
@@ -1,10 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a SplitButton with initialFocus is rendered', () => {
|
6
6
|
cy.visitStory('SplitButton', 'With initialFocus');
|
7
7
|
});
|
8
|
-
(0,
|
8
|
+
(0, _cypressCucumberPreprocessor.Then)('the SplitButton button is focused', () => {
|
9
9
|
cy.focused().should('have.attr', 'data-test', 'dhis2-uicore-splitbutton-button');
|
10
10
|
});
|
@@ -1,31 +1,29 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
require("
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
(0, _steps.Given)('a SplitButton is rendered', () => {
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a SplitButton is rendered', () => {
|
8
6
|
cy.visitStory('SplitButton', 'Default');
|
9
7
|
});
|
10
|
-
(0,
|
8
|
+
(0, _cypressCucumberPreprocessor.Given)('the SplitButton menu is open', () => {
|
11
9
|
cy.get('[data-test="dhis2-uicore-splitbutton-toggle"]').click();
|
12
10
|
cy.get('[data-test="dhis2-uicore-splitbutton-menu"]').should('be.visible');
|
13
11
|
});
|
14
|
-
(0,
|
12
|
+
(0, _cypressCucumberPreprocessor.Given)('the SplitButton menu is closed', () => {
|
15
13
|
cy.get('[data-test="dhis2-uicore-splitbutton-menu"]').should('not.exist');
|
16
14
|
});
|
17
|
-
(0,
|
15
|
+
(0, _cypressCucumberPreprocessor.When)('the user clicks the backdrop Layer', () => {
|
18
16
|
cy.get('[data-test="dhis2-uicore-layer"]').click();
|
19
17
|
});
|
20
|
-
(0,
|
18
|
+
(0, _cypressCucumberPreprocessor.Then)('the menu is not visible', () => {
|
21
19
|
cy.get('[data-test="dhis2-uicore-splitbutton-menu"]').should('not.exist');
|
22
20
|
});
|
23
|
-
(0,
|
21
|
+
(0, _cypressCucumberPreprocessor.Then)('the component is not visible', () => {
|
24
22
|
cy.contains('Component').should('not.exist');
|
25
23
|
});
|
26
|
-
(0,
|
24
|
+
(0, _cypressCucumberPreprocessor.Then)('the menu is visible', () => {
|
27
25
|
cy.get('[data-test="dhis2-uicore-splitbutton-menu"]').should('be.visible');
|
28
26
|
});
|
29
|
-
(0,
|
27
|
+
(0, _cypressCucumberPreprocessor.Then)('the component is visible', () => {
|
30
28
|
cy.contains('Component').should('be.visible');
|
31
29
|
});
|
@@ -1,13 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
require("
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
(0, _steps.Given)('a SplitButton with onClick hander is rendered', () => {
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a SplitButton with onClick hander is rendered', () => {
|
8
6
|
cy.visitStory('SplitButton', 'With onClick');
|
9
7
|
});
|
10
|
-
(0,
|
8
|
+
(0, _cypressCucumberPreprocessor.Then)('the onClick handler is called', () => {
|
11
9
|
cy.window().its('onClick').should('be.calledWith', {
|
12
10
|
name: 'Button',
|
13
11
|
value: 'default',
|
@@ -1,23 +1,23 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.Given)('a disabled SplitButton is rendered', () => {
|
6
6
|
cy.visitStory('SplitButton', 'With disabled');
|
7
7
|
});
|
8
|
-
(0,
|
8
|
+
(0, _cypressCucumberPreprocessor.When)('the user clicks the SplitButton Button', () => {
|
9
9
|
cy.get('[data-test="dhis2-uicore-splitbutton-button"]').click({
|
10
10
|
force: true
|
11
11
|
});
|
12
12
|
});
|
13
|
-
(0,
|
13
|
+
(0, _cypressCucumberPreprocessor.Then)('the SplitButton Button is not focused', () => {
|
14
14
|
cy.focused().should('not.exist');
|
15
15
|
});
|
16
|
-
(0,
|
16
|
+
(0, _cypressCucumberPreprocessor.When)('the user clicks the SplitButton Toggle', () => {
|
17
17
|
cy.get('[data-test="dhis2-uicore-splitbutton-toggle"]').click({
|
18
18
|
force: true
|
19
19
|
});
|
20
20
|
});
|
21
|
-
(0,
|
21
|
+
(0, _cypressCucumberPreprocessor.Then)('the SplitButton Toggle is not focused', () => {
|
22
22
|
cy.focused().should('not.exist');
|
23
23
|
});
|
@@ -1,10 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _cypressCucumberPreprocessor = require("@badeball/cypress-cucumber-preprocessor");
|
4
4
|
|
5
|
-
(0,
|
5
|
+
(0, _cypressCucumberPreprocessor.When)('the SplitButton is clicked', () => {
|
6
6
|
cy.get('[data-test="dhis2-uicore-splitbutton-button"]').click();
|
7
7
|
});
|
8
|
-
(0,
|
8
|
+
(0, _cypressCucumberPreprocessor.When)('the SplitButton toggle is clicked', () => {
|
9
9
|
cy.get('[data-test="dhis2-uicore-splitbutton-toggle"]').click();
|
10
10
|
});
|
@@ -23,8 +23,6 @@ var _react = _interopRequireWildcard(require("react"));
|
|
23
23
|
|
24
24
|
var _index = require("../index.js");
|
25
25
|
|
26
|
-
var _index2 = _interopRequireDefault(require("../locales/index.js"));
|
27
|
-
|
28
26
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
29
27
|
|
30
28
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
@@ -50,18 +48,6 @@ class SplitButton extends _react.Component {
|
|
50
48
|
|
51
49
|
_defineProperty(this, "anchorRef", /*#__PURE__*/_react.default.createRef());
|
52
50
|
|
53
|
-
_defineProperty(this, "handleKeyDown", event => {
|
54
|
-
event.preventDefault();
|
55
|
-
|
56
|
-
if (event.key === 'Escape' && this.state.open) {
|
57
|
-
event.stopPropagation();
|
58
|
-
this.setState({
|
59
|
-
open: false
|
60
|
-
});
|
61
|
-
this.anchorRef.current && this.anchorRef.current.focus();
|
62
|
-
}
|
63
|
-
});
|
64
|
-
|
65
51
|
_defineProperty(this, "onClick", (payload, event) => {
|
66
52
|
if (this.props.onClick) {
|
67
53
|
this.props.onClick({
|
@@ -72,19 +58,9 @@ class SplitButton extends _react.Component {
|
|
72
58
|
}
|
73
59
|
});
|
74
60
|
|
75
|
-
_defineProperty(this, "onToggle", () => {
|
76
|
-
this.
|
77
|
-
|
78
|
-
}));
|
79
|
-
});
|
80
|
-
}
|
81
|
-
|
82
|
-
componentDidMount() {
|
83
|
-
document.addEventListener('keydown', this.handleKeyDown);
|
84
|
-
}
|
85
|
-
|
86
|
-
componentWillUnmount() {
|
87
|
-
document.removeEventListener('keydown', this.handleKeyDown);
|
61
|
+
_defineProperty(this, "onToggle", () => this.setState({
|
62
|
+
open: !this.state.open
|
63
|
+
}));
|
88
64
|
}
|
89
65
|
|
90
66
|
render() {
|
@@ -143,9 +119,7 @@ class SplitButton extends _react.Component {
|
|
143
119
|
type: type,
|
144
120
|
tabIndex: tabIndex,
|
145
121
|
className: (0, _classnames.default)(className, rightButton.className),
|
146
|
-
dataTest: "".concat(dataTest, "-toggle")
|
147
|
-
title: _index2.default.t('Toggle dropdown'),
|
148
|
-
"aria-label": _index2.default.t('Toggle dropdown')
|
122
|
+
dataTest: "".concat(dataTest, "-toggle")
|
149
123
|
}, arrow), open && /*#__PURE__*/_react.default.createElement(_layer.Layer, {
|
150
124
|
onBackdropClick: this.onToggle,
|
151
125
|
transparent: true
|