@instructure/ui-toggle-details 10.16.1-snapshot-0 → 10.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/es/ToggleDetails/__new-tests__/ToggleDetails.test.js +39 -30
- package/es/ToggleDetails/index.js +56 -40
- package/es/ToggleGroup/__new-tests__/ToggleGroup.test.js +61 -45
- package/es/ToggleGroup/index.js +48 -31
- package/lib/ToggleDetails/__new-tests__/ToggleDetails.test.js +48 -39
- package/lib/ToggleDetails/index.js +54 -40
- package/lib/ToggleGroup/__new-tests__/ToggleGroup.test.js +69 -53
- package/lib/ToggleGroup/index.js +48 -32
- package/package.json +19 -19
- package/src/ToggleDetails/__new-tests__/ToggleDetails.test.tsx +0 -1
- package/src/ToggleDetails/index.tsx +3 -3
- package/src/ToggleGroup/__new-tests__/ToggleGroup.test.tsx +0 -1
- package/src/ToggleGroup/index.tsx +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/ToggleDetails/__new-tests__/ToggleDetails.test.d.ts.map +1 -1
- package/types/ToggleDetails/index.d.ts +7 -9
- package/types/ToggleDetails/index.d.ts.map +1 -1
- package/types/ToggleGroup/__new-tests__/ToggleGroup.test.d.ts.map +1 -1
- package/types/ToggleGroup/index.d.ts +4 -4
- package/types/ToggleGroup/index.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [10.16.1
|
|
6
|
+
## [10.16.1](https://github.com/instructure/instructure-ui/compare/v10.16.0...v10.16.1) (2025-04-22)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-toggle-details
|
|
9
9
|
|
|
@@ -23,13 +23,13 @@ var _ToggleDetails, _ToggleDetails2, _ToggleDetails3, _ToggleDetails4, _ToggleDe
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import React from 'react';
|
|
27
26
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
27
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
29
28
|
import userEvent from '@testing-library/user-event';
|
|
30
29
|
import { vi } from 'vitest';
|
|
31
30
|
import '@testing-library/jest-dom';
|
|
32
31
|
import { ToggleDetails } from '../index';
|
|
32
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
33
33
|
describe('<ToggleDetails />', () => {
|
|
34
34
|
let consoleWarningMock;
|
|
35
35
|
let consoleErrorMock;
|
|
@@ -43,41 +43,45 @@ describe('<ToggleDetails />', () => {
|
|
|
43
43
|
consoleErrorMock.mockRestore();
|
|
44
44
|
});
|
|
45
45
|
it('should hide its content', async () => {
|
|
46
|
-
render(_ToggleDetails || (_ToggleDetails =
|
|
47
|
-
summary: "Click me"
|
|
48
|
-
|
|
46
|
+
render(_ToggleDetails || (_ToggleDetails = _jsx(ToggleDetails, {
|
|
47
|
+
summary: "Click me",
|
|
48
|
+
children: "Content"
|
|
49
|
+
})));
|
|
49
50
|
const content = screen.queryByText('Content');
|
|
50
51
|
expect(content).not.toBeInTheDocument();
|
|
51
52
|
});
|
|
52
53
|
it('should place the icon after the summary when prop is set', async () => {
|
|
53
|
-
const _render = render(_ToggleDetails2 || (_ToggleDetails2 =
|
|
54
|
+
const _render = render(_ToggleDetails2 || (_ToggleDetails2 = _jsx(ToggleDetails, {
|
|
54
55
|
iconPosition: "end",
|
|
55
|
-
summary: "Click me"
|
|
56
|
-
|
|
56
|
+
summary: "Click me",
|
|
57
|
+
children: "Content"
|
|
58
|
+
}))),
|
|
57
59
|
container = _render.container;
|
|
58
60
|
const summary = container.querySelector('[class$="-toggleDetails__summaryText"]');
|
|
59
61
|
const icon = container.querySelector('[class$="-toggleDetails__icon"]');
|
|
60
62
|
expect(icon === null || icon === void 0 ? void 0 : icon.previousSibling).toBe(summary);
|
|
61
63
|
});
|
|
62
64
|
it('should have an aria-controls attribute', async () => {
|
|
63
|
-
const _render2 = render(_ToggleDetails3 || (_ToggleDetails3 =
|
|
64
|
-
summary: "Click me"
|
|
65
|
-
|
|
65
|
+
const _render2 = render(_ToggleDetails3 || (_ToggleDetails3 = _jsx(ToggleDetails, {
|
|
66
|
+
summary: "Click me",
|
|
67
|
+
children: "Details"
|
|
68
|
+
}))),
|
|
66
69
|
container = _render2.container;
|
|
67
70
|
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
68
71
|
const content = container.querySelector('[class$="-toggleDetails__details"]');
|
|
69
72
|
expect(toggle).toHaveAttribute('aria-controls', content === null || content === void 0 ? void 0 : content.id);
|
|
70
73
|
});
|
|
71
74
|
it('should have an aria-expanded attribute', async () => {
|
|
72
|
-
const _render3 = render(_ToggleDetails4 || (_ToggleDetails4 =
|
|
73
|
-
summary: "Click me"
|
|
74
|
-
|
|
75
|
+
const _render3 = render(_ToggleDetails4 || (_ToggleDetails4 = _jsx(ToggleDetails, {
|
|
76
|
+
summary: "Click me",
|
|
77
|
+
children: "Details"
|
|
78
|
+
}))),
|
|
75
79
|
container = _render3.container;
|
|
76
80
|
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
77
81
|
expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
78
82
|
});
|
|
79
83
|
it('should not have aria attributes when it has no children', async () => {
|
|
80
|
-
render(_ToggleDetails5 || (_ToggleDetails5 =
|
|
84
|
+
render(_ToggleDetails5 || (_ToggleDetails5 = _jsx(ToggleDetails, {
|
|
81
85
|
summary: "Click me",
|
|
82
86
|
"data-testid": "td__0"
|
|
83
87
|
})));
|
|
@@ -86,9 +90,10 @@ describe('<ToggleDetails />', () => {
|
|
|
86
90
|
expect(toggle).not.toHaveAttribute('aria-expanded');
|
|
87
91
|
});
|
|
88
92
|
it('should toggle on click events', async () => {
|
|
89
|
-
const _render4 = render(_ToggleDetails6 || (_ToggleDetails6 =
|
|
90
|
-
summary: "Click me"
|
|
91
|
-
|
|
93
|
+
const _render4 = render(_ToggleDetails6 || (_ToggleDetails6 = _jsx(ToggleDetails, {
|
|
94
|
+
summary: "Click me",
|
|
95
|
+
children: "Details"
|
|
96
|
+
}))),
|
|
92
97
|
container = _render4.container;
|
|
93
98
|
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
94
99
|
expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
@@ -99,11 +104,12 @@ describe('<ToggleDetails />', () => {
|
|
|
99
104
|
});
|
|
100
105
|
it('should call onToggle on click events', async () => {
|
|
101
106
|
const onToggle = vi.fn();
|
|
102
|
-
render(
|
|
107
|
+
render(_jsx(ToggleDetails, {
|
|
103
108
|
summary: "Click me",
|
|
104
109
|
expanded: false,
|
|
105
|
-
onToggle: onToggle
|
|
106
|
-
|
|
110
|
+
onToggle: onToggle,
|
|
111
|
+
children: "Details"
|
|
112
|
+
}));
|
|
107
113
|
await userEvent.click(screen.getByText('Click me'));
|
|
108
114
|
await waitFor(() => {
|
|
109
115
|
const args = onToggle.mock.calls[0];
|
|
@@ -114,7 +120,7 @@ describe('<ToggleDetails />', () => {
|
|
|
114
120
|
});
|
|
115
121
|
it('should call onToggle on click events when it has no children', async () => {
|
|
116
122
|
const onToggle = vi.fn();
|
|
117
|
-
render(
|
|
123
|
+
render(_jsx(ToggleDetails, {
|
|
118
124
|
summary: "Click me",
|
|
119
125
|
expanded: false,
|
|
120
126
|
onToggle: onToggle,
|
|
@@ -130,10 +136,11 @@ describe('<ToggleDetails />', () => {
|
|
|
130
136
|
});
|
|
131
137
|
});
|
|
132
138
|
it('should be initialized by defaultExpanded prop', async () => {
|
|
133
|
-
const _render5 = render(_ToggleDetails7 || (_ToggleDetails7 =
|
|
139
|
+
const _render5 = render(_ToggleDetails7 || (_ToggleDetails7 = _jsx(ToggleDetails, {
|
|
134
140
|
summary: "Click me",
|
|
135
|
-
defaultExpanded: true
|
|
136
|
-
|
|
141
|
+
defaultExpanded: true,
|
|
142
|
+
children: "Content"
|
|
143
|
+
}))),
|
|
137
144
|
container = _render5.container;
|
|
138
145
|
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
139
146
|
const content = container.querySelector('[class$="-toggleDetails__details"]');
|
|
@@ -141,9 +148,10 @@ describe('<ToggleDetails />', () => {
|
|
|
141
148
|
expect(content).toHaveTextContent('Content');
|
|
142
149
|
});
|
|
143
150
|
it('should meet a11y standards', async () => {
|
|
144
|
-
const _render6 = render(_ToggleDetails8 || (_ToggleDetails8 =
|
|
145
|
-
summary: "Click me"
|
|
146
|
-
|
|
151
|
+
const _render6 = render(_ToggleDetails8 || (_ToggleDetails8 = _jsx(ToggleDetails, {
|
|
152
|
+
summary: "Click me",
|
|
153
|
+
children: "Content"
|
|
154
|
+
}))),
|
|
147
155
|
container = _render6.container;
|
|
148
156
|
const axeCheck = await runAxeCheck(container);
|
|
149
157
|
expect(axeCheck).toBe(true);
|
|
@@ -151,12 +159,13 @@ describe('<ToggleDetails />', () => {
|
|
|
151
159
|
it('focuses with the focus helper', async () => {
|
|
152
160
|
var _toggleRef;
|
|
153
161
|
let toggleRef;
|
|
154
|
-
const _render7 = render(
|
|
162
|
+
const _render7 = render(_jsx(ToggleDetails, {
|
|
155
163
|
summary: "Click me",
|
|
156
164
|
ref: el => {
|
|
157
165
|
toggleRef = el;
|
|
158
|
-
}
|
|
159
|
-
|
|
166
|
+
},
|
|
167
|
+
children: "Content"
|
|
168
|
+
})),
|
|
160
169
|
container = _render7.container;
|
|
161
170
|
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
162
171
|
expect(document.activeElement).not.toBe(toggle);
|
|
@@ -22,18 +22,19 @@ var _dec, _dec2, _class, _ToggleDetails;
|
|
|
22
22
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
import
|
|
25
|
+
|
|
26
|
+
import { Component } from 'react';
|
|
27
27
|
import { Button } from '@instructure/ui-buttons';
|
|
28
28
|
import { IconArrowOpenEndSolid, IconArrowOpenDownSolid } from '@instructure/ui-icons';
|
|
29
29
|
import { Expandable } from '@instructure/ui-expandable';
|
|
30
30
|
import { omitProps, pickProps } from '@instructure/ui-react-utils';
|
|
31
31
|
import { isActiveElement } from '@instructure/ui-dom-utils';
|
|
32
32
|
import { testable } from '@instructure/ui-testable';
|
|
33
|
-
import { withStyle
|
|
33
|
+
import { withStyle } from '@instructure/emotion';
|
|
34
34
|
import generateStyle from './styles';
|
|
35
35
|
import generateComponentTheme from './theme';
|
|
36
36
|
import { allowedProps, propTypes } from './props';
|
|
37
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
37
38
|
/**
|
|
38
39
|
---
|
|
39
40
|
category: components
|
|
@@ -71,11 +72,13 @@ let ToggleDetails = (_dec = withStyle(generateStyle, generateComponentTheme), _d
|
|
|
71
72
|
const _this$props3 = this.props,
|
|
72
73
|
summary = _this$props3.summary,
|
|
73
74
|
iconPosition = _this$props3.iconPosition;
|
|
74
|
-
return
|
|
75
|
-
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.summary
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
return _jsxs("span", {
|
|
76
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.summary,
|
|
77
|
+
children: [iconPosition === 'start' && this.renderIcon(expanded), _jsx("span", {
|
|
78
|
+
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.summaryText,
|
|
79
|
+
children: summary
|
|
80
|
+
}), iconPosition === 'end' && this.renderIcon(expanded)]
|
|
81
|
+
});
|
|
79
82
|
}
|
|
80
83
|
renderToggle(toggleProps, expanded) {
|
|
81
84
|
const variant = this.props.variant;
|
|
@@ -91,32 +94,39 @@ let ToggleDetails = (_dec = withStyle(generateStyle, generateComponentTheme), _d
|
|
|
91
94
|
};
|
|
92
95
|
const summary = this.renderSummary(expanded);
|
|
93
96
|
if (variant === 'filled') {
|
|
94
|
-
return
|
|
97
|
+
return _jsx(Button, {
|
|
98
|
+
...props,
|
|
95
99
|
display: "block",
|
|
96
100
|
textAlign: "start",
|
|
97
|
-
elementRef: this.getButtonRef
|
|
98
|
-
|
|
101
|
+
elementRef: this.getButtonRef,
|
|
102
|
+
children: summary
|
|
103
|
+
});
|
|
99
104
|
} else if (props.href) {
|
|
100
105
|
var _this$props$styles3;
|
|
101
|
-
return
|
|
106
|
+
return _jsx("a", {
|
|
107
|
+
...props,
|
|
102
108
|
css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.toggle,
|
|
103
|
-
ref: this.getButtonRef
|
|
104
|
-
|
|
109
|
+
ref: this.getButtonRef,
|
|
110
|
+
children: summary
|
|
111
|
+
});
|
|
105
112
|
} else {
|
|
106
113
|
var _this$props$styles4;
|
|
107
|
-
return
|
|
114
|
+
return _jsx("button", {
|
|
115
|
+
...props,
|
|
108
116
|
type: "button",
|
|
109
117
|
css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.toggle,
|
|
110
|
-
ref: this.getButtonRef
|
|
111
|
-
|
|
118
|
+
ref: this.getButtonRef,
|
|
119
|
+
children: summary
|
|
120
|
+
});
|
|
112
121
|
}
|
|
113
122
|
}
|
|
114
123
|
renderIcon(expanded) {
|
|
115
124
|
var _this$props$styles5;
|
|
116
125
|
const Icon = expanded ? this.props.iconExpanded : this.props.icon;
|
|
117
|
-
return this.props.children && Icon ?
|
|
118
|
-
css: (_this$props$styles5 = this.props.styles) === null || _this$props$styles5 === void 0 ? void 0 : _this$props$styles5.icon
|
|
119
|
-
|
|
126
|
+
return this.props.children && Icon ? _jsx("span", {
|
|
127
|
+
css: (_this$props$styles5 = this.props.styles) === null || _this$props$styles5 === void 0 ? void 0 : _this$props$styles5.icon,
|
|
128
|
+
children: _jsx(Icon, {})
|
|
129
|
+
}) : null;
|
|
120
130
|
}
|
|
121
131
|
renderDetails(expanded, detailsProps) {
|
|
122
132
|
var _this$props$styles6;
|
|
@@ -126,31 +136,37 @@ let ToggleDetails = (_dec = withStyle(generateStyle, generateComponentTheme), _d
|
|
|
126
136
|
} : {
|
|
127
137
|
display: 'none'
|
|
128
138
|
};
|
|
129
|
-
return
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
return _jsx("div", {
|
|
140
|
+
...detailsProps,
|
|
141
|
+
css: [(_this$props$styles6 = this.props.styles) === null || _this$props$styles6 === void 0 ? void 0 : _this$props$styles6.details, expandedStyles],
|
|
142
|
+
children: expanded && this.renderContent()
|
|
143
|
+
});
|
|
132
144
|
}
|
|
133
145
|
renderContent() {
|
|
134
146
|
var _this$props$styles7;
|
|
135
|
-
return
|
|
136
|
-
css: (_this$props$styles7 = this.props.styles) === null || _this$props$styles7 === void 0 ? void 0 : _this$props$styles7.content
|
|
137
|
-
|
|
147
|
+
return _jsx("div", {
|
|
148
|
+
css: (_this$props$styles7 = this.props.styles) === null || _this$props$styles7 === void 0 ? void 0 : _this$props$styles7.content,
|
|
149
|
+
children: this.props.children
|
|
150
|
+
});
|
|
138
151
|
}
|
|
139
152
|
render() {
|
|
140
|
-
return
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
return _jsx(Expandable, {
|
|
154
|
+
...pickProps(this.props, Expandable.allowedProps),
|
|
155
|
+
onToggle: this.handleToggle,
|
|
156
|
+
children: ({
|
|
157
|
+
expanded,
|
|
158
|
+
getToggleProps,
|
|
159
|
+
getDetailsProps
|
|
160
|
+
}) => {
|
|
161
|
+
var _this$props$styles8;
|
|
162
|
+
return _jsxs("div", {
|
|
163
|
+
css: (_this$props$styles8 = this.props.styles) === null || _this$props$styles8 === void 0 ? void 0 : _this$props$styles8.toggleDetails,
|
|
164
|
+
ref: el => {
|
|
165
|
+
this.ref = el;
|
|
166
|
+
},
|
|
167
|
+
children: [this.renderToggle(getToggleProps(), expanded), this.renderDetails(expanded, getDetailsProps())]
|
|
168
|
+
});
|
|
169
|
+
}
|
|
154
170
|
});
|
|
155
171
|
}
|
|
156
172
|
}, _ToggleDetails.displayName = "ToggleDetails", _ToggleDetails.componentId = 'ToggleDetails', _ToggleDetails.allowedProps = allowedProps, _ToggleDetails.propTypes = propTypes, _ToggleDetails.defaultProps = {
|
|
@@ -23,13 +23,13 @@ var _ToggleGroup, _ToggleGroup2, _ToggleGroup3, _ToggleGroup4, _ToggleGroup5, _s
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import React from 'react';
|
|
27
26
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
27
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
29
28
|
import userEvent from '@testing-library/user-event';
|
|
30
29
|
import { vi } from 'vitest';
|
|
31
30
|
import '@testing-library/jest-dom';
|
|
32
31
|
import { ToggleGroup } from '../index';
|
|
32
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
33
33
|
describe('<ToggleGroup />', () => {
|
|
34
34
|
let consoleWarningMock;
|
|
35
35
|
let consoleErrorMock;
|
|
@@ -43,24 +43,26 @@ describe('<ToggleGroup />', () => {
|
|
|
43
43
|
consoleErrorMock.mockRestore();
|
|
44
44
|
});
|
|
45
45
|
it('should show its summary and hide its children by default', async () => {
|
|
46
|
-
render(_ToggleGroup || (_ToggleGroup =
|
|
46
|
+
render(_ToggleGroup || (_ToggleGroup = _jsx(ToggleGroup, {
|
|
47
47
|
"data-testId": "toggle-group",
|
|
48
48
|
transition: false,
|
|
49
49
|
summary: "This is the summary section",
|
|
50
|
-
toggleLabel: "This is the toggleLabel"
|
|
51
|
-
|
|
50
|
+
toggleLabel: "This is the toggleLabel",
|
|
51
|
+
children: "This is the details section"
|
|
52
|
+
})));
|
|
52
53
|
const toggleGroup = screen.getByTestId('toggle-group');
|
|
53
54
|
expect(toggleGroup).toHaveTextContent('This is the summary section');
|
|
54
55
|
expect(toggleGroup).not.toHaveTextContent('This is the details section');
|
|
55
56
|
});
|
|
56
57
|
it('should render with children showing with the defaultExpanded prop', async () => {
|
|
57
|
-
const _render = render(_ToggleGroup2 || (_ToggleGroup2 =
|
|
58
|
+
const _render = render(_ToggleGroup2 || (_ToggleGroup2 = _jsx(ToggleGroup, {
|
|
58
59
|
"data-testId": "toggle-group",
|
|
59
60
|
transition: false,
|
|
60
61
|
summary: "This is the summary section",
|
|
61
62
|
toggleLabel: "This is the toggleLabel",
|
|
62
|
-
defaultExpanded: true
|
|
63
|
-
|
|
63
|
+
defaultExpanded: true,
|
|
64
|
+
children: "This is the details section"
|
|
65
|
+
}))),
|
|
64
66
|
container = _render.container;
|
|
65
67
|
const toggleGroup = screen.getByTestId('toggle-group');
|
|
66
68
|
const toggle = container.querySelector('button');
|
|
@@ -68,33 +70,36 @@ describe('<ToggleGroup />', () => {
|
|
|
68
70
|
expect(toggleGroup).toHaveTextContent('This is the details section');
|
|
69
71
|
});
|
|
70
72
|
it('should have an aria-controls attribute', async () => {
|
|
71
|
-
const _render2 = render(_ToggleGroup3 || (_ToggleGroup3 =
|
|
73
|
+
const _render2 = render(_ToggleGroup3 || (_ToggleGroup3 = _jsx(ToggleGroup, {
|
|
72
74
|
transition: false,
|
|
73
75
|
summary: "This is the summary section",
|
|
74
76
|
toggleLabel: "This is the toggleLabel",
|
|
75
|
-
defaultExpanded: true
|
|
76
|
-
|
|
77
|
+
defaultExpanded: true,
|
|
78
|
+
children: "This is the details section"
|
|
79
|
+
}))),
|
|
77
80
|
container = _render2.container;
|
|
78
81
|
const content = screen.getByText('This is the details section');
|
|
79
82
|
const toggle = container.querySelector('button');
|
|
80
83
|
expect(toggle).toHaveAttribute('aria-controls', content.id);
|
|
81
84
|
});
|
|
82
85
|
it('should have an aria-expanded attribute', async () => {
|
|
83
|
-
const _render3 = render(_ToggleGroup4 || (_ToggleGroup4 =
|
|
86
|
+
const _render3 = render(_ToggleGroup4 || (_ToggleGroup4 = _jsx(ToggleGroup, {
|
|
84
87
|
transition: false,
|
|
85
88
|
summary: "This is the summary section",
|
|
86
|
-
toggleLabel: "This is the toggleLabel"
|
|
87
|
-
|
|
89
|
+
toggleLabel: "This is the toggleLabel",
|
|
90
|
+
children: "This is the details section"
|
|
91
|
+
}))),
|
|
88
92
|
container = _render3.container;
|
|
89
93
|
const toggle = container.querySelector('button');
|
|
90
94
|
expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
91
95
|
});
|
|
92
96
|
it('should toggle on click events', async () => {
|
|
93
|
-
const _render4 = render(_ToggleGroup5 || (_ToggleGroup5 =
|
|
97
|
+
const _render4 = render(_ToggleGroup5 || (_ToggleGroup5 = _jsx(ToggleGroup, {
|
|
94
98
|
transition: false,
|
|
95
99
|
summary: "This is the summary section",
|
|
96
|
-
toggleLabel: "This is the toggleLabel"
|
|
97
|
-
|
|
100
|
+
toggleLabel: "This is the toggleLabel",
|
|
101
|
+
children: "This is the details section"
|
|
102
|
+
}))),
|
|
98
103
|
container = _render4.container;
|
|
99
104
|
const toggle = container.querySelector('button');
|
|
100
105
|
expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
@@ -105,13 +110,14 @@ describe('<ToggleGroup />', () => {
|
|
|
105
110
|
});
|
|
106
111
|
it('should call onToggle on click events', async () => {
|
|
107
112
|
const onToggle = vi.fn();
|
|
108
|
-
const _render5 = render(
|
|
113
|
+
const _render5 = render(_jsx(ToggleGroup, {
|
|
109
114
|
transition: false,
|
|
110
115
|
summary: "This is the summary section",
|
|
111
116
|
toggleLabel: "This is the toggleLabel",
|
|
112
117
|
expanded: false,
|
|
113
|
-
onToggle: onToggle
|
|
114
|
-
|
|
118
|
+
onToggle: onToggle,
|
|
119
|
+
children: "This is the details section"
|
|
120
|
+
})),
|
|
115
121
|
container = _render5.container;
|
|
116
122
|
const toggle = container.querySelector('button');
|
|
117
123
|
await userEvent.click(toggle);
|
|
@@ -123,11 +129,12 @@ describe('<ToggleGroup />', () => {
|
|
|
123
129
|
});
|
|
124
130
|
});
|
|
125
131
|
it('should update the toggle screenreader label based on the expanded state', async () => {
|
|
126
|
-
const _render6 = render(
|
|
132
|
+
const _render6 = render(_jsx(ToggleGroup, {
|
|
127
133
|
transition: false,
|
|
128
134
|
summary: "This is the summary section",
|
|
129
|
-
toggleLabel: expanded => expanded ? 'Hide content' : 'Show content'
|
|
130
|
-
|
|
135
|
+
toggleLabel: expanded => expanded ? 'Hide content' : 'Show content',
|
|
136
|
+
children: "This is the details section"
|
|
137
|
+
})),
|
|
131
138
|
container = _render6.container;
|
|
132
139
|
const toggle = container.querySelector('button');
|
|
133
140
|
const scrContent = container.querySelector('[class$="-screenReaderContent"]');
|
|
@@ -138,29 +145,36 @@ describe('<ToggleGroup />', () => {
|
|
|
138
145
|
});
|
|
139
146
|
});
|
|
140
147
|
it('should accept custom icons', async () => {
|
|
141
|
-
const Icon = _svg || (_svg =
|
|
148
|
+
const Icon = _svg || (_svg = _jsxs("svg", {
|
|
142
149
|
height: "50",
|
|
143
|
-
width: "50"
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
width: "50",
|
|
151
|
+
children: [_jsx("title", {
|
|
152
|
+
children: "Icon collapsed"
|
|
153
|
+
}), _jsx("circle", {
|
|
154
|
+
cx: "25",
|
|
155
|
+
cy: "25",
|
|
156
|
+
r: "20"
|
|
157
|
+
})]
|
|
158
|
+
}));
|
|
159
|
+
const IconExpanded = _svg2 || (_svg2 = _jsxs("svg", {
|
|
150
160
|
height: "50",
|
|
151
|
-
width: "50"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
161
|
+
width: "50",
|
|
162
|
+
children: [_jsx("title", {
|
|
163
|
+
children: "Icon expanded"
|
|
164
|
+
}), _jsx("circle", {
|
|
165
|
+
cx: "25",
|
|
166
|
+
cy: "25",
|
|
167
|
+
r: "20"
|
|
168
|
+
})]
|
|
169
|
+
}));
|
|
170
|
+
const _render7 = render(_jsx(ToggleGroup, {
|
|
158
171
|
transition: false,
|
|
159
172
|
summary: "This is the summary section",
|
|
160
173
|
toggleLabel: "This is the toggleLabel",
|
|
161
174
|
icon: () => Icon,
|
|
162
|
-
iconExpanded: () => IconExpanded
|
|
163
|
-
|
|
175
|
+
iconExpanded: () => IconExpanded,
|
|
176
|
+
children: "This is the details section"
|
|
177
|
+
})),
|
|
164
178
|
container = _render7.container;
|
|
165
179
|
const toggle = container.querySelector('button');
|
|
166
180
|
const svg = container.querySelector('svg');
|
|
@@ -171,11 +185,12 @@ describe('<ToggleGroup />', () => {
|
|
|
171
185
|
});
|
|
172
186
|
});
|
|
173
187
|
it('should meet a11y standards', async () => {
|
|
174
|
-
const _render8 = render(_ToggleGroup6 || (_ToggleGroup6 =
|
|
188
|
+
const _render8 = render(_ToggleGroup6 || (_ToggleGroup6 = _jsx(ToggleGroup, {
|
|
175
189
|
transition: false,
|
|
176
190
|
summary: "This is the summary section",
|
|
177
|
-
toggleLabel: "This is the toggleLabel"
|
|
178
|
-
|
|
191
|
+
toggleLabel: "This is the toggleLabel",
|
|
192
|
+
children: "This is the details section"
|
|
193
|
+
}))),
|
|
179
194
|
container = _render8.container;
|
|
180
195
|
const axeCheck = await runAxeCheck(container);
|
|
181
196
|
expect(axeCheck).toBe(true);
|
|
@@ -183,15 +198,16 @@ describe('<ToggleGroup />', () => {
|
|
|
183
198
|
it('focuses with the focus helper', async () => {
|
|
184
199
|
var _toggleRef;
|
|
185
200
|
let toggleRef;
|
|
186
|
-
const _render9 = render(
|
|
201
|
+
const _render9 = render(_jsx(ToggleGroup, {
|
|
187
202
|
"data-testId": "toggle-group",
|
|
188
203
|
transition: false,
|
|
189
204
|
summary: "This is the summary section",
|
|
190
205
|
toggleLabel: "This is the toggleLabel",
|
|
191
206
|
ref: el => {
|
|
192
207
|
toggleRef = el;
|
|
193
|
-
}
|
|
194
|
-
|
|
208
|
+
},
|
|
209
|
+
children: "This is the details section"
|
|
210
|
+
})),
|
|
195
211
|
container = _render9.container;
|
|
196
212
|
const toggle = container.querySelector('button');
|
|
197
213
|
expect(document.activeElement).not.toBe(toggle);
|
package/es/ToggleGroup/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var _dec, _dec2, _class, _ToggleGroup;
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import
|
|
26
|
+
import { Component } from 'react';
|
|
27
27
|
import { omitProps, pickProps, getElementType, callRenderProp } from '@instructure/ui-react-utils';
|
|
28
28
|
import { IconButton } from '@instructure/ui-buttons';
|
|
29
29
|
import { Transition } from '@instructure/ui-motion';
|
|
@@ -43,6 +43,7 @@ import generateComponentTheme from './theme';
|
|
|
43
43
|
category: components
|
|
44
44
|
---
|
|
45
45
|
**/
|
|
46
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
46
47
|
let ToggleGroup = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_ToggleGroup = class ToggleGroup extends Component {
|
|
47
48
|
constructor(...args) {
|
|
48
49
|
super(...args);
|
|
@@ -91,49 +92,65 @@ let ToggleGroup = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
|
|
|
91
92
|
const props = {
|
|
92
93
|
...toggleProps
|
|
93
94
|
};
|
|
94
|
-
return
|
|
95
|
+
return _jsx(IconButton, {
|
|
96
|
+
...props,
|
|
95
97
|
withBackground: false,
|
|
96
98
|
withBorder: false,
|
|
97
99
|
size: size === 'large' ? 'medium' : 'small',
|
|
98
100
|
elementRef: this.handleButtonRef,
|
|
99
|
-
screenReaderLabel: label
|
|
100
|
-
|
|
101
|
+
screenReaderLabel: label,
|
|
102
|
+
children: this.renderIcon(expanded)
|
|
103
|
+
});
|
|
101
104
|
}
|
|
102
105
|
renderDetails(detailsProps) {
|
|
103
106
|
const styles = this.props.styles;
|
|
104
|
-
return
|
|
107
|
+
return _jsx(View, {
|
|
108
|
+
...detailsProps,
|
|
105
109
|
display: "block",
|
|
106
110
|
borderWidth: "small none none none",
|
|
107
|
-
borderColor: styles === null || styles === void 0 ? void 0 : styles.borderColor
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
borderColor: styles === null || styles === void 0 ? void 0 : styles.borderColor,
|
|
112
|
+
children: this.props.transition && this._shouldTransition ? _jsx(Transition, {
|
|
113
|
+
transitionOnMount: true,
|
|
114
|
+
in: true,
|
|
115
|
+
type: "fade",
|
|
116
|
+
children: this.props.children
|
|
117
|
+
}) : this.props.children
|
|
118
|
+
});
|
|
113
119
|
}
|
|
114
120
|
render() {
|
|
115
121
|
const Element = getElementType(ToggleGroup, this.props);
|
|
116
122
|
const styles = this.props.styles;
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
123
|
+
return _jsx(Expandable, {
|
|
124
|
+
...pickProps(this.props, Expandable.allowedProps),
|
|
125
|
+
children: ({
|
|
126
|
+
expanded,
|
|
127
|
+
getToggleProps,
|
|
128
|
+
getDetailsProps
|
|
129
|
+
}) => {
|
|
130
|
+
return _jsxs(View, {
|
|
131
|
+
...omitProps(this.props, ToggleGroup.allowedProps),
|
|
132
|
+
borderWidth: this.props.border ? 'small' : 'none',
|
|
133
|
+
as: Element,
|
|
134
|
+
elementRef: this.handleRef,
|
|
135
|
+
display: "block",
|
|
136
|
+
borderRadius: "medium",
|
|
137
|
+
background: "primary",
|
|
138
|
+
borderColor: styles === null || styles === void 0 ? void 0 : styles.borderColor,
|
|
139
|
+
children: [_jsxs(Flex, {
|
|
140
|
+
padding: this.props.size === 'small' ? 'x-small' : 'small small small x-small',
|
|
141
|
+
children: [_jsx(Flex.Item, {
|
|
142
|
+
children: this.renderToggle(getToggleProps(), expanded)
|
|
143
|
+
}), _jsx(Flex.Item, {
|
|
144
|
+
shouldGrow: true,
|
|
145
|
+
shouldShrink: true,
|
|
146
|
+
padding: "0 0 0 x-small",
|
|
147
|
+
children: this.props.summary
|
|
148
|
+
})]
|
|
149
|
+
}), expanded ? this.renderDetails(getDetailsProps()) : _jsx("span", {
|
|
150
|
+
...getDetailsProps()
|
|
151
|
+
})]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
137
154
|
});
|
|
138
155
|
}
|
|
139
156
|
}, _ToggleGroup.displayName = "ToggleGroup", _ToggleGroup.componentId = 'ToggleGroup', _ToggleGroup.allowedProps = allowedProps, _ToggleGroup.propTypes = propTypes, _ToggleGroup.defaultProps = {
|