@instructure/ui-editable 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/Editable/__new-tests__/Editable.test.js +28 -21
- package/es/InPlaceEdit/__new-tests__/InPlaceEdit.test.js +19 -16
- package/es/InPlaceEdit/index.js +27 -20
- package/lib/Editable/__new-tests__/Editable.test.js +50 -43
- package/lib/InPlaceEdit/__new-tests__/InPlaceEdit.test.js +31 -29
- package/lib/InPlaceEdit/index.js +26 -19
- package/package.json +14 -14
- package/src/Editable/__new-tests__/Editable.test.tsx +0 -1
- package/src/Editable/index.tsx +1 -1
- package/src/InPlaceEdit/__new-tests__/InPlaceEdit.test.tsx +0 -1
- package/src/InPlaceEdit/index.tsx +1 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Editable/__new-tests__/Editable.test.d.ts.map +1 -1
- package/types/Editable/index.d.ts +2 -2
- package/types/Editable/index.d.ts.map +1 -1
- package/types/InPlaceEdit/__new-tests__/InPlaceEdit.test.d.ts.map +1 -1
- package/types/InPlaceEdit/index.d.ts +4 -6
- package/types/InPlaceEdit/index.d.ts.map +1 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var _react = _interopRequireDefault(require("react"));
|
|
5
|
-
var _react2 = require("@testing-library/react");
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
6
4
|
var _vitest = require("vitest");
|
|
7
5
|
require("@testing-library/jest-dom");
|
|
8
6
|
var _index = require("../index");
|
|
9
7
|
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
8
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
9
|
var _div;
|
|
11
10
|
/*
|
|
12
11
|
* The MIT License (MIT)
|
|
@@ -33,12 +32,14 @@ var _div;
|
|
|
33
32
|
*/
|
|
34
33
|
const VIEWER_TEXT = 'viewer-text';
|
|
35
34
|
const EDIT_BUTTON_TEXT = 'edit-button-text';
|
|
36
|
-
const renderViewer = () => _div || (_div =
|
|
35
|
+
const renderViewer = () => _div || (_div = (0, _jsxRuntime.jsx)("div", {
|
|
36
|
+
children: VIEWER_TEXT
|
|
37
|
+
}));
|
|
37
38
|
const renderEditor = ({
|
|
38
39
|
editorRef,
|
|
39
40
|
onBlur
|
|
40
41
|
}) => {
|
|
41
|
-
return
|
|
42
|
+
return (0, _jsxRuntime.jsx)("input", {
|
|
42
43
|
"data-testid": "input-editor",
|
|
43
44
|
ref: editorRef,
|
|
44
45
|
onBlur: onBlur,
|
|
@@ -78,21 +79,21 @@ describe('<InPlaceEdit />', () => {
|
|
|
78
79
|
consoleErrorMock.mockRestore();
|
|
79
80
|
});
|
|
80
81
|
it('should render view mode', () => {
|
|
81
|
-
(0,
|
|
82
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.InPlaceEdit, {
|
|
82
83
|
mode: "view",
|
|
83
84
|
onChangeMode: _vitest.vi.fn(),
|
|
84
85
|
renderViewer: renderViewer,
|
|
85
86
|
renderEditor: renderEditor,
|
|
86
87
|
renderEditButton: renderEditButton
|
|
87
88
|
}));
|
|
88
|
-
const viewModeText =
|
|
89
|
-
const editButton =
|
|
89
|
+
const viewModeText = _react.screen.getByText(VIEWER_TEXT);
|
|
90
|
+
const editButton = _react.screen.getByRole('button');
|
|
90
91
|
expect(viewModeText).toBeInTheDocument();
|
|
91
92
|
expect(editButton).toBeInTheDocument();
|
|
92
93
|
expect(editButton).toHaveTextContent(EDIT_BUTTON_TEXT);
|
|
93
94
|
});
|
|
94
95
|
it('should render view mode with string button label', () => {
|
|
95
|
-
const _render = (0,
|
|
96
|
+
const _render = (0, _react.render)((0, _jsxRuntime.jsx)(_index.InPlaceEdit, {
|
|
96
97
|
mode: "view",
|
|
97
98
|
onChangeMode: _vitest.vi.fn(),
|
|
98
99
|
renderViewer: renderViewer,
|
|
@@ -100,8 +101,8 @@ describe('<InPlaceEdit />', () => {
|
|
|
100
101
|
renderEditButton: renderEditButton
|
|
101
102
|
})),
|
|
102
103
|
container = _render.container;
|
|
103
|
-
const viewModeText =
|
|
104
|
-
const editButton =
|
|
104
|
+
const viewModeText = _react.screen.getByText(VIEWER_TEXT);
|
|
105
|
+
const editButton = _react.screen.getByRole('button');
|
|
105
106
|
const buttonLabel = container.querySelector("[class$='-screenReaderContent']");
|
|
106
107
|
expect(viewModeText).toBeInTheDocument();
|
|
107
108
|
expect(editButton).toBeInTheDocument();
|
|
@@ -109,39 +110,40 @@ describe('<InPlaceEdit />', () => {
|
|
|
109
110
|
expect(buttonLabel).toHaveTextContent(EDIT_BUTTON_TEXT);
|
|
110
111
|
});
|
|
111
112
|
it('should render edit mode', () => {
|
|
112
|
-
(0,
|
|
113
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.InPlaceEdit, {
|
|
113
114
|
mode: "edit",
|
|
114
115
|
onChangeMode: _vitest.vi.fn(),
|
|
115
116
|
renderViewer: renderViewer,
|
|
116
117
|
renderEditor: renderEditor,
|
|
117
118
|
renderEditButton: renderEditButton
|
|
118
119
|
}));
|
|
119
|
-
const inputForEdit =
|
|
120
|
+
const inputForEdit = _react.screen.getByTestId('input-editor');
|
|
120
121
|
expect(inputForEdit).toBeInTheDocument();
|
|
121
122
|
expect(document.activeElement).toBe(inputForEdit);
|
|
122
123
|
});
|
|
123
124
|
it('should render a custom edit button', () => {
|
|
124
125
|
var _button;
|
|
125
126
|
const customButtonText = 'custom-button-text';
|
|
126
|
-
(0,
|
|
127
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.InPlaceEdit, {
|
|
127
128
|
mode: "view",
|
|
128
129
|
onChangeMode: _vitest.vi.fn(),
|
|
129
130
|
renderViewer: renderViewer,
|
|
130
131
|
renderEditor: renderEditor,
|
|
131
132
|
renderEditButton: () => {
|
|
132
|
-
return _button || (_button =
|
|
133
|
-
"data-testid": "custom_button"
|
|
134
|
-
|
|
133
|
+
return _button || (_button = (0, _jsxRuntime.jsx)("button", {
|
|
134
|
+
"data-testid": "custom_button",
|
|
135
|
+
children: customButtonText
|
|
136
|
+
}));
|
|
135
137
|
}
|
|
136
138
|
}));
|
|
137
|
-
const viewModeText =
|
|
138
|
-
const customEditButton =
|
|
139
|
+
const viewModeText = _react.screen.getByText(VIEWER_TEXT);
|
|
140
|
+
const customEditButton = _react.screen.getByTestId('custom_button');
|
|
139
141
|
expect(viewModeText).toBeInTheDocument();
|
|
140
142
|
expect(customEditButton).toBeInTheDocument();
|
|
141
143
|
expect(customEditButton).toHaveTextContent(customButtonText);
|
|
142
144
|
});
|
|
143
145
|
it('should switch mode to edit via props, and focus the editor', () => {
|
|
144
|
-
const _render2 = (0,
|
|
146
|
+
const _render2 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.InPlaceEdit, {
|
|
145
147
|
mode: "view",
|
|
146
148
|
onChangeMode: _vitest.vi.fn(),
|
|
147
149
|
renderViewer: renderViewer,
|
|
@@ -150,24 +152,24 @@ describe('<InPlaceEdit />', () => {
|
|
|
150
152
|
})),
|
|
151
153
|
rerender = _render2.rerender,
|
|
152
154
|
container = _render2.container;
|
|
153
|
-
const viewModeText =
|
|
155
|
+
const viewModeText = _react.screen.getByText(VIEWER_TEXT);
|
|
154
156
|
expect(viewModeText).toBeInTheDocument();
|
|
155
157
|
|
|
156
158
|
// Simulate mode prop change
|
|
157
|
-
rerender(
|
|
159
|
+
rerender((0, _jsxRuntime.jsx)(_index.InPlaceEdit, {
|
|
158
160
|
mode: "edit",
|
|
159
161
|
onChangeMode: _vitest.vi.fn(),
|
|
160
162
|
renderViewer: renderViewer,
|
|
161
163
|
renderEditor: renderEditor,
|
|
162
164
|
renderEditButton: renderEditButton
|
|
163
165
|
}));
|
|
164
|
-
const inputForEdit =
|
|
166
|
+
const inputForEdit = _react.screen.getByTestId('input-editor');
|
|
165
167
|
expect(container).not.toHaveTextContent(VIEWER_TEXT);
|
|
166
168
|
expect(inputForEdit).toBeInTheDocument();
|
|
167
169
|
expect(document.activeElement).toBe(inputForEdit);
|
|
168
170
|
});
|
|
169
171
|
it('should switch mode to view via props, and focus the edit button', () => {
|
|
170
|
-
const _render3 = (0,
|
|
172
|
+
const _render3 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.InPlaceEdit, {
|
|
171
173
|
mode: "edit",
|
|
172
174
|
onChangeMode: _vitest.vi.fn(),
|
|
173
175
|
renderViewer: renderViewer,
|
|
@@ -176,12 +178,12 @@ describe('<InPlaceEdit />', () => {
|
|
|
176
178
|
})),
|
|
177
179
|
rerender = _render3.rerender,
|
|
178
180
|
container = _render3.container;
|
|
179
|
-
const inputForEdit =
|
|
181
|
+
const inputForEdit = _react.screen.getByTestId('input-editor');
|
|
180
182
|
expect(container).not.toHaveTextContent(VIEWER_TEXT);
|
|
181
183
|
expect(inputForEdit).toBeInTheDocument();
|
|
182
184
|
|
|
183
185
|
// Simulate mode prop change
|
|
184
|
-
rerender(
|
|
186
|
+
rerender((0, _jsxRuntime.jsx)(_index.InPlaceEdit, {
|
|
185
187
|
mode: "view",
|
|
186
188
|
onChangeMode: _vitest.vi.fn(),
|
|
187
189
|
renderViewer: renderViewer,
|
|
@@ -189,7 +191,7 @@ describe('<InPlaceEdit />', () => {
|
|
|
189
191
|
renderEditButton: renderEditButton
|
|
190
192
|
}));
|
|
191
193
|
const inputForEditAfterModeChange = container.querySelector("[id='input-editor']");
|
|
192
|
-
const editButton =
|
|
194
|
+
const editButton = _react.screen.getByRole('button');
|
|
193
195
|
expect(container).toHaveTextContent(VIEWER_TEXT);
|
|
194
196
|
expect(inputForEditAfterModeChange).not.toBeInTheDocument();
|
|
195
197
|
expect(editButton).toBeInTheDocument();
|
|
@@ -197,7 +199,7 @@ describe('<InPlaceEdit />', () => {
|
|
|
197
199
|
expect(document.activeElement).toBe(editButton);
|
|
198
200
|
});
|
|
199
201
|
it('should meet a11y standards in view mode', async () => {
|
|
200
|
-
const _render4 = (0,
|
|
202
|
+
const _render4 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.InPlaceEdit, {
|
|
201
203
|
mode: "view",
|
|
202
204
|
onChangeMode: _vitest.vi.fn(),
|
|
203
205
|
renderViewer: renderViewer,
|
|
@@ -209,7 +211,7 @@ describe('<InPlaceEdit />', () => {
|
|
|
209
211
|
expect(axeCheck).toBe(true);
|
|
210
212
|
});
|
|
211
213
|
it('should meet a11y standards in edit mode', async () => {
|
|
212
|
-
const _render5 = (0,
|
|
214
|
+
const _render5 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.InPlaceEdit, {
|
|
213
215
|
mode: "edit",
|
|
214
216
|
onChangeMode: _vitest.vi.fn(),
|
|
215
217
|
renderViewer: renderViewer,
|
package/lib/InPlaceEdit/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var _View = require("@instructure/ui-view/lib/View");
|
|
|
16
16
|
var _Editable = require("../Editable");
|
|
17
17
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
18
18
|
var _props = require("./props");
|
|
19
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
19
20
|
var _dec, _class, _InPlaceEdit;
|
|
20
21
|
/*
|
|
21
22
|
* The MIT License (MIT)
|
|
@@ -40,7 +41,6 @@ var _dec, _class, _InPlaceEdit;
|
|
|
40
41
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
41
42
|
* SOFTWARE.
|
|
42
43
|
*/
|
|
43
|
-
/** @jsx jsx */
|
|
44
44
|
/**
|
|
45
45
|
---
|
|
46
46
|
category: components
|
|
@@ -66,16 +66,20 @@ let InPlaceEdit = exports.InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.
|
|
|
66
66
|
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
67
67
|
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
68
68
|
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
69
|
-
return (0,
|
|
69
|
+
return (0, _jsxRuntime.jsxs)(_Flex.Flex, {
|
|
70
70
|
display: this.props.inline ? 'inline-flex' : 'flex',
|
|
71
71
|
direction: flexDir,
|
|
72
|
-
justifyItems: justifyItems
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
justifyItems: justifyItems,
|
|
73
|
+
...getContainerProps(),
|
|
74
|
+
children: [(0, _jsxRuntime.jsxs)(_Flex.Flex.Item, {
|
|
75
|
+
shouldGrow: true,
|
|
76
|
+
shouldShrink: true,
|
|
77
|
+
children: [this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())]
|
|
78
|
+
}), (0, _jsxRuntime.jsx)(_Flex.Flex.Item, {
|
|
79
|
+
margin: buttonMargin,
|
|
80
|
+
children: this.renderEditButton(getEditButtonProps())
|
|
81
|
+
})]
|
|
82
|
+
});
|
|
79
83
|
};
|
|
80
84
|
(0, _console.logWarn)(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
|
|
81
85
|
}
|
|
@@ -98,18 +102,19 @@ let InPlaceEdit = exports.InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.
|
|
|
98
102
|
showFocusRing = _this$props3.showFocusRing,
|
|
99
103
|
renderEditor = _this$props3.renderEditor;
|
|
100
104
|
const isEditMode = !readOnly && mode === 'edit';
|
|
101
|
-
return isEditMode ? (0,
|
|
105
|
+
return isEditMode ? (0, _jsxRuntime.jsx)(_View.View, {
|
|
102
106
|
as: "span",
|
|
103
107
|
display: "block",
|
|
104
108
|
withFocusOutline: showFocusRing,
|
|
105
109
|
position: "relative",
|
|
106
110
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.inPlaceEdit,
|
|
107
111
|
borderRadius: "medium",
|
|
108
|
-
margin: "auto"
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
margin: "auto",
|
|
113
|
+
children: renderEditor({
|
|
114
|
+
onBlur,
|
|
115
|
+
editorRef
|
|
116
|
+
})
|
|
117
|
+
}) : null;
|
|
113
118
|
}
|
|
114
119
|
renderViewer({
|
|
115
120
|
readOnly,
|
|
@@ -137,7 +142,7 @@ let InPlaceEdit = exports.InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.
|
|
|
137
142
|
onChange = _this$props4.onChange,
|
|
138
143
|
onChangeMode = _this$props4.onChangeMode,
|
|
139
144
|
readOnly = _this$props4.readOnly;
|
|
140
|
-
return (0,
|
|
145
|
+
return (0, _jsxRuntime.jsx)(_Editable.Editable, {
|
|
141
146
|
mode: mode,
|
|
142
147
|
onChangeMode: onChangeMode,
|
|
143
148
|
render: this.renderAll,
|
|
@@ -161,11 +166,13 @@ let InPlaceEdit = exports.InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.
|
|
|
161
166
|
if (readOnly) {
|
|
162
167
|
return null;
|
|
163
168
|
}
|
|
164
|
-
return (0,
|
|
169
|
+
return (0, _jsxRuntime.jsx)(_IconButton.IconButton, {
|
|
165
170
|
size: "small",
|
|
166
171
|
screenReaderLabel: label,
|
|
167
172
|
withBackground: false,
|
|
168
|
-
withBorder: false
|
|
169
|
-
|
|
173
|
+
withBorder: false,
|
|
174
|
+
...buttonProps,
|
|
175
|
+
children: isVisible ? _IconEditLine.IconEditLine : null
|
|
176
|
+
});
|
|
170
177
|
}, _InPlaceEdit)) || _class);
|
|
171
178
|
var _default = exports.default = InPlaceEdit;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-editable",
|
|
3
|
-
"version": "10.16.1
|
|
3
|
+
"version": "10.16.1",
|
|
4
4
|
"description": "A UI component library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-axe-check": "10.16.1
|
|
27
|
-
"@instructure/ui-babel-preset": "10.16.1
|
|
26
|
+
"@instructure/ui-axe-check": "10.16.1",
|
|
27
|
+
"@instructure/ui-babel-preset": "10.16.1",
|
|
28
28
|
"@testing-library/jest-dom": "^6.6.3",
|
|
29
29
|
"@testing-library/react": "^16.0.1",
|
|
30
30
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/runtime": "^7.26.0",
|
|
35
|
-
"@instructure/console": "10.16.1
|
|
36
|
-
"@instructure/emotion": "10.16.1
|
|
37
|
-
"@instructure/shared-types": "10.16.1
|
|
38
|
-
"@instructure/ui-a11y-content": "10.16.1
|
|
39
|
-
"@instructure/ui-buttons": "10.16.1
|
|
40
|
-
"@instructure/ui-dom-utils": "10.16.1
|
|
41
|
-
"@instructure/ui-flex": "10.16.1
|
|
42
|
-
"@instructure/ui-focusable": "10.16.1
|
|
43
|
-
"@instructure/ui-icons": "10.16.1
|
|
44
|
-
"@instructure/ui-utils": "10.16.1
|
|
45
|
-
"@instructure/ui-view": "10.16.1
|
|
35
|
+
"@instructure/console": "10.16.1",
|
|
36
|
+
"@instructure/emotion": "10.16.1",
|
|
37
|
+
"@instructure/shared-types": "10.16.1",
|
|
38
|
+
"@instructure/ui-a11y-content": "10.16.1",
|
|
39
|
+
"@instructure/ui-buttons": "10.16.1",
|
|
40
|
+
"@instructure/ui-dom-utils": "10.16.1",
|
|
41
|
+
"@instructure/ui-flex": "10.16.1",
|
|
42
|
+
"@instructure/ui-focusable": "10.16.1",
|
|
43
|
+
"@instructure/ui-icons": "10.16.1",
|
|
44
|
+
"@instructure/ui-utils": "10.16.1",
|
|
45
|
+
"@instructure/ui-view": "10.16.1",
|
|
46
46
|
"prop-types": "^15.8.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
package/src/Editable/index.tsx
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import
|
|
24
|
+
import { Component } from 'react'
|
|
25
25
|
|
|
26
26
|
import { deepEqual } from '@instructure/ui-utils'
|
|
27
27
|
import { logWarn as warn } from '@instructure/console'
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
/** @jsx jsx */
|
|
26
25
|
import { Component } from 'react'
|
|
27
26
|
|
|
28
27
|
import { Flex } from '@instructure/ui-flex'
|
|
@@ -31,7 +30,7 @@ import type { IconButtonProps } from '@instructure/ui-buttons'
|
|
|
31
30
|
import { IconEditLine } from '@instructure/ui-icons'
|
|
32
31
|
import { logWarn as warn } from '@instructure/console'
|
|
33
32
|
import { createChainedFunction } from '@instructure/ui-utils'
|
|
34
|
-
import { withStyle
|
|
33
|
+
import { withStyle } from '@instructure/emotion'
|
|
35
34
|
import { View } from '@instructure/ui-view'
|
|
36
35
|
|
|
37
36
|
import { Editable } from '../Editable'
|