@instructure/ui-text-input 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/TextInput/__new-tests__/TextInput.test.js +15 -15
- package/es/TextInput/index.js +33 -24
- package/lib/TextInput/__new-tests__/TextInput.test.js +30 -30
- package/lib/TextInput/index.js +32 -24
- package/package.json +16 -16
- package/src/TextInput/__new-tests__/TextInput.test.tsx +0 -1
- package/src/TextInput/index.tsx +4 -5
- package/src/TextInput/props.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/TextInput/__new-tests__/TextInput.test.d.ts.map +1 -1
- package/types/TextInput/index.d.ts +3 -5
- package/types/TextInput/index.d.ts.map +1 -1
- package/types/TextInput/props.d.ts +1 -1
- package/types/TextInput/props.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-text-input
|
|
9
9
|
|
|
@@ -23,13 +23,13 @@ var _TextInput, _TextInput2, _TextInput3, _TextInput4, _TextInput5, _TextInput6,
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import React from 'react';
|
|
27
26
|
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
|
|
28
27
|
import userEvent from '@testing-library/user-event';
|
|
29
28
|
import { vi } from 'vitest';
|
|
30
29
|
import '@testing-library/jest-dom';
|
|
31
30
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
32
31
|
import { TextInput } from '../index';
|
|
32
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
33
33
|
describe('<TextInput/>', () => {
|
|
34
34
|
let consoleErrorMock;
|
|
35
35
|
beforeEach(() => {
|
|
@@ -40,7 +40,7 @@ describe('<TextInput/>', () => {
|
|
|
40
40
|
consoleErrorMock.mockRestore();
|
|
41
41
|
});
|
|
42
42
|
it('should include a label', async () => {
|
|
43
|
-
const _render = render(_TextInput || (_TextInput =
|
|
43
|
+
const _render = render(_TextInput || (_TextInput = _jsx(TextInput, {
|
|
44
44
|
renderLabel: "Name"
|
|
45
45
|
}))),
|
|
46
46
|
container = _render.container;
|
|
@@ -50,7 +50,7 @@ describe('<TextInput/>', () => {
|
|
|
50
50
|
it('should focus the input when focus is called', async () => {
|
|
51
51
|
var _ref;
|
|
52
52
|
let ref;
|
|
53
|
-
render(
|
|
53
|
+
render(_jsx(TextInput, {
|
|
54
54
|
renderLabel: "Name"
|
|
55
55
|
//@ts-expect-error TODO this is coming from ReactComponentWrapper
|
|
56
56
|
,
|
|
@@ -64,7 +64,7 @@ describe('<TextInput/>', () => {
|
|
|
64
64
|
});
|
|
65
65
|
it('should provide an inputRef prop', async () => {
|
|
66
66
|
const inputRef = vi.fn();
|
|
67
|
-
render(
|
|
67
|
+
render(_jsx(TextInput, {
|
|
68
68
|
renderLabel: "Name",
|
|
69
69
|
inputRef: inputRef
|
|
70
70
|
}));
|
|
@@ -74,7 +74,7 @@ describe('<TextInput/>', () => {
|
|
|
74
74
|
it('should provide a value getter', async () => {
|
|
75
75
|
var _ref2;
|
|
76
76
|
let ref;
|
|
77
|
-
render(
|
|
77
|
+
render(_jsx(TextInput, {
|
|
78
78
|
renderLabel: "Name",
|
|
79
79
|
defaultValue: "bar"
|
|
80
80
|
//@ts-expect-error TODO this is coming from ReactComponentWrapper
|
|
@@ -86,7 +86,7 @@ describe('<TextInput/>', () => {
|
|
|
86
86
|
expect((_ref2 = ref) === null || _ref2 === void 0 ? void 0 : _ref2.value).toBe('bar');
|
|
87
87
|
});
|
|
88
88
|
it('should let aria-describedby through', async () => {
|
|
89
|
-
render(_TextInput2 || (_TextInput2 =
|
|
89
|
+
render(_TextInput2 || (_TextInput2 = _jsx(TextInput, {
|
|
90
90
|
renderLabel: "Name",
|
|
91
91
|
"aria-describedby": "abcd"
|
|
92
92
|
})));
|
|
@@ -96,7 +96,7 @@ describe('<TextInput/>', () => {
|
|
|
96
96
|
describe('events', () => {
|
|
97
97
|
it('responds to onChange event', async () => {
|
|
98
98
|
const onChange = vi.fn();
|
|
99
|
-
render(
|
|
99
|
+
render(_jsx(TextInput, {
|
|
100
100
|
renderLabel: "Name",
|
|
101
101
|
onChange: onChange
|
|
102
102
|
}));
|
|
@@ -112,7 +112,7 @@ describe('<TextInput/>', () => {
|
|
|
112
112
|
});
|
|
113
113
|
it('responds to onBlur event', async () => {
|
|
114
114
|
const onBlur = vi.fn();
|
|
115
|
-
render(
|
|
115
|
+
render(_jsx(TextInput, {
|
|
116
116
|
renderLabel: "Name",
|
|
117
117
|
onBlur: onBlur
|
|
118
118
|
}));
|
|
@@ -124,7 +124,7 @@ describe('<TextInput/>', () => {
|
|
|
124
124
|
});
|
|
125
125
|
it('responds to onFocus event', async () => {
|
|
126
126
|
const onFocus = vi.fn();
|
|
127
|
-
render(
|
|
127
|
+
render(_jsx(TextInput, {
|
|
128
128
|
renderLabel: "Name",
|
|
129
129
|
onFocus: onFocus
|
|
130
130
|
}));
|
|
@@ -137,7 +137,7 @@ describe('<TextInput/>', () => {
|
|
|
137
137
|
});
|
|
138
138
|
describe('interaction', () => {
|
|
139
139
|
it('should set the disabled attribute when `interaction` is disabled', async () => {
|
|
140
|
-
render(_TextInput3 || (_TextInput3 =
|
|
140
|
+
render(_TextInput3 || (_TextInput3 = _jsx(TextInput, {
|
|
141
141
|
renderLabel: "Name",
|
|
142
142
|
interaction: "disabled"
|
|
143
143
|
})));
|
|
@@ -145,7 +145,7 @@ describe('<TextInput/>', () => {
|
|
|
145
145
|
expect(input).toHaveAttribute('disabled');
|
|
146
146
|
});
|
|
147
147
|
it('should set the disabled attribute when `disabled` is set', async () => {
|
|
148
|
-
render(_TextInput4 || (_TextInput4 =
|
|
148
|
+
render(_TextInput4 || (_TextInput4 = _jsx(TextInput, {
|
|
149
149
|
renderLabel: "Name",
|
|
150
150
|
disabled: true
|
|
151
151
|
})));
|
|
@@ -153,7 +153,7 @@ describe('<TextInput/>', () => {
|
|
|
153
153
|
expect(input).toHaveAttribute('disabled');
|
|
154
154
|
});
|
|
155
155
|
it('should set the readonly attribute when `interaction` is readonly', async () => {
|
|
156
|
-
render(_TextInput5 || (_TextInput5 =
|
|
156
|
+
render(_TextInput5 || (_TextInput5 = _jsx(TextInput, {
|
|
157
157
|
renderLabel: "Name",
|
|
158
158
|
interaction: "readonly"
|
|
159
159
|
})));
|
|
@@ -161,7 +161,7 @@ describe('<TextInput/>', () => {
|
|
|
161
161
|
expect(input).toHaveAttribute('readonly');
|
|
162
162
|
});
|
|
163
163
|
it('should set the readonly attribute when `readOnly` is set', async () => {
|
|
164
|
-
render(_TextInput6 || (_TextInput6 =
|
|
164
|
+
render(_TextInput6 || (_TextInput6 = _jsx(TextInput, {
|
|
165
165
|
renderLabel: "Name",
|
|
166
166
|
readOnly: true
|
|
167
167
|
})));
|
|
@@ -171,7 +171,7 @@ describe('<TextInput/>', () => {
|
|
|
171
171
|
});
|
|
172
172
|
describe('for a11y', () => {
|
|
173
173
|
it('should meet standards', async () => {
|
|
174
|
-
const _render2 = render(_TextInput7 || (_TextInput7 =
|
|
174
|
+
const _render2 = render(_TextInput7 || (_TextInput7 = _jsx(TextInput, {
|
|
175
175
|
renderLabel: "Name"
|
|
176
176
|
}))),
|
|
177
177
|
container = _render2.container;
|
|
@@ -179,7 +179,7 @@ describe('<TextInput/>', () => {
|
|
|
179
179
|
expect(axeCheck).toBe(true);
|
|
180
180
|
});
|
|
181
181
|
it('should set aria-invalid when errors prop is set', async () => {
|
|
182
|
-
render(
|
|
182
|
+
render(_jsx(TextInput, {
|
|
183
183
|
renderLabel: "Name",
|
|
184
184
|
messages: [{
|
|
185
185
|
type: 'error',
|
package/es/TextInput/index.js
CHANGED
|
@@ -25,13 +25,12 @@ var _dec, _dec2, _dec3, _class, _TextInput;
|
|
|
25
25
|
* SOFTWARE.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
import React, { Component } from 'react';
|
|
28
|
+
import { Fragment, Component } from 'react';
|
|
30
29
|
import { callRenderProp, getInteraction, passthroughProps, withDeterministicId } from '@instructure/ui-react-utils';
|
|
31
30
|
import { isActiveElement, addEventListener } from '@instructure/ui-dom-utils';
|
|
32
31
|
import { FormField } from '@instructure/ui-form-field';
|
|
33
32
|
import { testable } from '@instructure/ui-testable';
|
|
34
|
-
import { withStyle
|
|
33
|
+
import { withStyle } from '@instructure/emotion';
|
|
35
34
|
import { hasVisibleChildren } from '@instructure/ui-a11y-utils';
|
|
36
35
|
import generateStyle from './styles';
|
|
37
36
|
import generateComponentTheme from './theme';
|
|
@@ -43,6 +42,7 @@ category: components
|
|
|
43
42
|
tags: form, field
|
|
44
43
|
---
|
|
45
44
|
**/
|
|
45
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
46
46
|
let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec3 = testable(), _dec(_class = _dec2(_class = _dec3(_class = (_TextInput = class TextInput extends Component {
|
|
47
47
|
constructor(props) {
|
|
48
48
|
super(props);
|
|
@@ -187,7 +187,8 @@ let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
|
|
|
187
187
|
if (props['aria-describedby']) {
|
|
188
188
|
descriptionIds = `${props['aria-describedby']}`;
|
|
189
189
|
}
|
|
190
|
-
return
|
|
190
|
+
return _jsx("input", {
|
|
191
|
+
...props,
|
|
191
192
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.textInput,
|
|
192
193
|
defaultValue: defaultValue,
|
|
193
194
|
value: value,
|
|
@@ -203,7 +204,7 @@ let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
|
|
|
203
204
|
size: htmlSize,
|
|
204
205
|
onChange: this.handleChange,
|
|
205
206
|
onBlur: this.handleBlur
|
|
206
|
-
})
|
|
207
|
+
});
|
|
207
208
|
}
|
|
208
209
|
getElementHasWidth(element) {
|
|
209
210
|
if (!element) {
|
|
@@ -238,11 +239,14 @@ let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
|
|
|
238
239
|
const afterElement = renderAfterInput ? callRenderProp(renderAfterInput) : null;
|
|
239
240
|
const renderBeforeOrAfter = !!beforeElement || !!afterElement || renderBeforeInput !== void 0 || renderAfterInput !== void 0;
|
|
240
241
|
const rawLabel = callRenderProp(renderLabel);
|
|
241
|
-
const label = hasVisibleChildren(rawLabel) ?
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
const label = hasVisibleChildren(rawLabel) ? _jsxs(Fragment, {
|
|
243
|
+
children: [rawLabel, isRequired && _jsxs("span", {
|
|
244
|
+
css: this.invalid ? styles === null || styles === void 0 ? void 0 : styles.requiredInvalid : {},
|
|
245
|
+
"aria-hidden": true,
|
|
246
|
+
children: [' ', "*"]
|
|
247
|
+
})]
|
|
248
|
+
}) : rawLabel;
|
|
249
|
+
return _jsx(FormField, {
|
|
246
250
|
id: this.id,
|
|
247
251
|
label: label,
|
|
248
252
|
messagesId: this._messagesId,
|
|
@@ -252,20 +256,25 @@ let TextInput = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
|
|
|
252
256
|
inputContainerRef: inputContainerRef,
|
|
253
257
|
layout: this.props.layout,
|
|
254
258
|
elementRef: this.handleRef,
|
|
255
|
-
margin: this.props.margin
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
259
|
+
margin: this.props.margin,
|
|
260
|
+
children: _jsx("span", {
|
|
261
|
+
css: styles === null || styles === void 0 ? void 0 : styles.facade,
|
|
262
|
+
children: renderBeforeOrAfter ? _jsxs("span", {
|
|
263
|
+
css: styles === null || styles === void 0 ? void 0 : styles.layout,
|
|
264
|
+
children: [beforeElement, _jsxs("span", {
|
|
265
|
+
css: styles === null || styles === void 0 ? void 0 : styles.inputLayout,
|
|
266
|
+
children: [this.renderInput(), afterElement && _jsx("span", {
|
|
267
|
+
css: styles === null || styles === void 0 ? void 0 : styles.afterElement,
|
|
268
|
+
ref: e => {
|
|
269
|
+
this._afterElement = e;
|
|
270
|
+
},
|
|
271
|
+
children: afterElement
|
|
272
|
+
})]
|
|
273
|
+
})]
|
|
274
|
+
}) : (/* If no prepended or appended content, don't render Flex layout */
|
|
275
|
+
this.renderInput())
|
|
276
|
+
})
|
|
277
|
+
});
|
|
269
278
|
}
|
|
270
279
|
}, _TextInput.displayName = "TextInput", _TextInput.componentId = 'TextInput', _TextInput.allowedProps = allowedProps, _TextInput.propTypes = propTypes, _TextInput.defaultProps = {
|
|
271
280
|
type: 'text',
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _react =
|
|
5
|
-
var _react2 = require("@testing-library/react");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
6
5
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
7
6
|
var _vitest = require("vitest");
|
|
8
7
|
require("@testing-library/jest-dom");
|
|
9
8
|
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
10
9
|
var _index = require("../index");
|
|
10
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
11
11
|
var _TextInput, _TextInput2, _TextInput3, _TextInput4, _TextInput5, _TextInput6, _TextInput7;
|
|
12
12
|
/*
|
|
13
13
|
* The MIT License (MIT)
|
|
@@ -42,7 +42,7 @@ describe('<TextInput/>', () => {
|
|
|
42
42
|
consoleErrorMock.mockRestore();
|
|
43
43
|
});
|
|
44
44
|
it('should include a label', async () => {
|
|
45
|
-
const _render = (0,
|
|
45
|
+
const _render = (0, _react.render)(_TextInput || (_TextInput = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
46
46
|
renderLabel: "Name"
|
|
47
47
|
}))),
|
|
48
48
|
container = _render.container;
|
|
@@ -52,7 +52,7 @@ describe('<TextInput/>', () => {
|
|
|
52
52
|
it('should focus the input when focus is called', async () => {
|
|
53
53
|
var _ref;
|
|
54
54
|
let ref;
|
|
55
|
-
(0,
|
|
55
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
56
56
|
renderLabel: "Name"
|
|
57
57
|
//@ts-expect-error TODO this is coming from ReactComponentWrapper
|
|
58
58
|
,
|
|
@@ -60,23 +60,23 @@ describe('<TextInput/>', () => {
|
|
|
60
60
|
ref = el;
|
|
61
61
|
}
|
|
62
62
|
}));
|
|
63
|
-
const input =
|
|
63
|
+
const input = _react.screen.getByRole('textbox');
|
|
64
64
|
(_ref = ref) === null || _ref === void 0 ? void 0 : _ref.focus();
|
|
65
65
|
expect(input).toHaveFocus();
|
|
66
66
|
});
|
|
67
67
|
it('should provide an inputRef prop', async () => {
|
|
68
68
|
const inputRef = _vitest.vi.fn();
|
|
69
|
-
(0,
|
|
69
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
70
70
|
renderLabel: "Name",
|
|
71
71
|
inputRef: inputRef
|
|
72
72
|
}));
|
|
73
|
-
const input =
|
|
73
|
+
const input = _react.screen.getByRole('textbox');
|
|
74
74
|
expect(inputRef).toHaveBeenCalledWith(input);
|
|
75
75
|
});
|
|
76
76
|
it('should provide a value getter', async () => {
|
|
77
77
|
var _ref2;
|
|
78
78
|
let ref;
|
|
79
|
-
(0,
|
|
79
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
80
80
|
renderLabel: "Name",
|
|
81
81
|
defaultValue: "bar"
|
|
82
82
|
//@ts-expect-error TODO this is coming from ReactComponentWrapper
|
|
@@ -88,92 +88,92 @@ describe('<TextInput/>', () => {
|
|
|
88
88
|
expect((_ref2 = ref) === null || _ref2 === void 0 ? void 0 : _ref2.value).toBe('bar');
|
|
89
89
|
});
|
|
90
90
|
it('should let aria-describedby through', async () => {
|
|
91
|
-
(0,
|
|
91
|
+
(0, _react.render)(_TextInput2 || (_TextInput2 = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
92
92
|
renderLabel: "Name",
|
|
93
93
|
"aria-describedby": "abcd"
|
|
94
94
|
})));
|
|
95
|
-
const input =
|
|
95
|
+
const input = _react.screen.getByRole('textbox');
|
|
96
96
|
expect(input).toHaveAttribute('aria-describedby', 'abcd');
|
|
97
97
|
});
|
|
98
98
|
describe('events', () => {
|
|
99
99
|
it('responds to onChange event', async () => {
|
|
100
100
|
const onChange = _vitest.vi.fn();
|
|
101
|
-
(0,
|
|
101
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
102
102
|
renderLabel: "Name",
|
|
103
103
|
onChange: onChange
|
|
104
104
|
}));
|
|
105
|
-
const input =
|
|
106
|
-
|
|
105
|
+
const input = _react.screen.getByRole('textbox');
|
|
106
|
+
_react.fireEvent.change(input, {
|
|
107
107
|
target: {
|
|
108
108
|
value: 'foo'
|
|
109
109
|
}
|
|
110
110
|
});
|
|
111
|
-
await (0,
|
|
111
|
+
await (0, _react.waitFor)(() => {
|
|
112
112
|
expect(onChange).toHaveBeenCalledTimes(1);
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
it('responds to onBlur event', async () => {
|
|
116
116
|
const onBlur = _vitest.vi.fn();
|
|
117
|
-
(0,
|
|
117
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
118
118
|
renderLabel: "Name",
|
|
119
119
|
onBlur: onBlur
|
|
120
120
|
}));
|
|
121
121
|
_userEvent.default.tab();
|
|
122
122
|
_userEvent.default.tab();
|
|
123
|
-
await (0,
|
|
123
|
+
await (0, _react.waitFor)(() => {
|
|
124
124
|
expect(onBlur).toHaveBeenCalled();
|
|
125
125
|
});
|
|
126
126
|
});
|
|
127
127
|
it('responds to onFocus event', async () => {
|
|
128
128
|
const onFocus = _vitest.vi.fn();
|
|
129
|
-
(0,
|
|
129
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
130
130
|
renderLabel: "Name",
|
|
131
131
|
onFocus: onFocus
|
|
132
132
|
}));
|
|
133
|
-
const input =
|
|
133
|
+
const input = _react.screen.getByRole('textbox');
|
|
134
134
|
input.focus();
|
|
135
|
-
await (0,
|
|
135
|
+
await (0, _react.waitFor)(() => {
|
|
136
136
|
expect(onFocus).toHaveBeenCalled();
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
139
|
});
|
|
140
140
|
describe('interaction', () => {
|
|
141
141
|
it('should set the disabled attribute when `interaction` is disabled', async () => {
|
|
142
|
-
(0,
|
|
142
|
+
(0, _react.render)(_TextInput3 || (_TextInput3 = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
143
143
|
renderLabel: "Name",
|
|
144
144
|
interaction: "disabled"
|
|
145
145
|
})));
|
|
146
|
-
const input =
|
|
146
|
+
const input = _react.screen.getByRole('textbox');
|
|
147
147
|
expect(input).toHaveAttribute('disabled');
|
|
148
148
|
});
|
|
149
149
|
it('should set the disabled attribute when `disabled` is set', async () => {
|
|
150
|
-
(0,
|
|
150
|
+
(0, _react.render)(_TextInput4 || (_TextInput4 = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
151
151
|
renderLabel: "Name",
|
|
152
152
|
disabled: true
|
|
153
153
|
})));
|
|
154
|
-
const input =
|
|
154
|
+
const input = _react.screen.getByRole('textbox');
|
|
155
155
|
expect(input).toHaveAttribute('disabled');
|
|
156
156
|
});
|
|
157
157
|
it('should set the readonly attribute when `interaction` is readonly', async () => {
|
|
158
|
-
(0,
|
|
158
|
+
(0, _react.render)(_TextInput5 || (_TextInput5 = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
159
159
|
renderLabel: "Name",
|
|
160
160
|
interaction: "readonly"
|
|
161
161
|
})));
|
|
162
|
-
const input =
|
|
162
|
+
const input = _react.screen.getByRole('textbox');
|
|
163
163
|
expect(input).toHaveAttribute('readonly');
|
|
164
164
|
});
|
|
165
165
|
it('should set the readonly attribute when `readOnly` is set', async () => {
|
|
166
|
-
(0,
|
|
166
|
+
(0, _react.render)(_TextInput6 || (_TextInput6 = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
167
167
|
renderLabel: "Name",
|
|
168
168
|
readOnly: true
|
|
169
169
|
})));
|
|
170
|
-
const input =
|
|
170
|
+
const input = _react.screen.getByRole('textbox');
|
|
171
171
|
expect(input).toHaveAttribute('readonly');
|
|
172
172
|
});
|
|
173
173
|
});
|
|
174
174
|
describe('for a11y', () => {
|
|
175
175
|
it('should meet standards', async () => {
|
|
176
|
-
const _render2 = (0,
|
|
176
|
+
const _render2 = (0, _react.render)(_TextInput7 || (_TextInput7 = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
177
177
|
renderLabel: "Name"
|
|
178
178
|
}))),
|
|
179
179
|
container = _render2.container;
|
|
@@ -181,14 +181,14 @@ describe('<TextInput/>', () => {
|
|
|
181
181
|
expect(axeCheck).toBe(true);
|
|
182
182
|
});
|
|
183
183
|
it('should set aria-invalid when errors prop is set', async () => {
|
|
184
|
-
(0,
|
|
184
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
185
185
|
renderLabel: "Name",
|
|
186
186
|
messages: [{
|
|
187
187
|
type: 'error',
|
|
188
188
|
text: 'some error message'
|
|
189
189
|
}]
|
|
190
190
|
}));
|
|
191
|
-
const input =
|
|
191
|
+
const input = _react.screen.getByRole('textbox');
|
|
192
192
|
expect(input).toHaveAttribute('aria-invalid');
|
|
193
193
|
});
|
|
194
194
|
});
|
package/lib/TextInput/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = exports.TextInput = void 0;
|
|
9
8
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
|
-
var _react =
|
|
9
|
+
var _react = require("react");
|
|
11
10
|
var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
|
|
12
11
|
var _getInteraction = require("@instructure/ui-react-utils/lib/getInteraction.js");
|
|
13
12
|
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
@@ -21,6 +20,7 @@ var _hasVisibleChildren = require("@instructure/ui-a11y-utils/lib/hasVisibleChil
|
|
|
21
20
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
22
21
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
23
22
|
var _props = require("./props");
|
|
23
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
24
24
|
const _excluded = ["type", "size", "htmlSize", "display", "textAlign", "placeholder", "value", "defaultValue", "isRequired", "onFocus"];
|
|
25
25
|
var _dec, _dec2, _dec3, _class, _TextInput;
|
|
26
26
|
/*
|
|
@@ -46,7 +46,6 @@ var _dec, _dec2, _dec3, _class, _TextInput;
|
|
|
46
46
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
47
47
|
* SOFTWARE.
|
|
48
48
|
*/
|
|
49
|
-
/** @jsx jsx */
|
|
50
49
|
/**
|
|
51
50
|
---
|
|
52
51
|
category: components
|
|
@@ -197,7 +196,8 @@ let TextInput = exports.TextInput = (_dec = (0, _withDeterministicId.withDetermi
|
|
|
197
196
|
if (props['aria-describedby']) {
|
|
198
197
|
descriptionIds = `${props['aria-describedby']}`;
|
|
199
198
|
}
|
|
200
|
-
return (0,
|
|
199
|
+
return (0, _jsxRuntime.jsx)("input", {
|
|
200
|
+
...props,
|
|
201
201
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.textInput,
|
|
202
202
|
defaultValue: defaultValue,
|
|
203
203
|
value: value,
|
|
@@ -213,7 +213,7 @@ let TextInput = exports.TextInput = (_dec = (0, _withDeterministicId.withDetermi
|
|
|
213
213
|
size: htmlSize,
|
|
214
214
|
onChange: this.handleChange,
|
|
215
215
|
onBlur: this.handleBlur
|
|
216
|
-
})
|
|
216
|
+
});
|
|
217
217
|
}
|
|
218
218
|
getElementHasWidth(element) {
|
|
219
219
|
if (!element) {
|
|
@@ -248,11 +248,14 @@ let TextInput = exports.TextInput = (_dec = (0, _withDeterministicId.withDetermi
|
|
|
248
248
|
const afterElement = renderAfterInput ? (0, _callRenderProp.callRenderProp)(renderAfterInput) : null;
|
|
249
249
|
const renderBeforeOrAfter = !!beforeElement || !!afterElement || renderBeforeInput !== void 0 || renderAfterInput !== void 0;
|
|
250
250
|
const rawLabel = (0, _callRenderProp.callRenderProp)(renderLabel);
|
|
251
|
-
const label = (0, _hasVisibleChildren.hasVisibleChildren)(rawLabel) ? (0,
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
251
|
+
const label = (0, _hasVisibleChildren.hasVisibleChildren)(rawLabel) ? (0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
252
|
+
children: [rawLabel, isRequired && (0, _jsxRuntime.jsxs)("span", {
|
|
253
|
+
css: this.invalid ? styles === null || styles === void 0 ? void 0 : styles.requiredInvalid : {},
|
|
254
|
+
"aria-hidden": true,
|
|
255
|
+
children: [' ', "*"]
|
|
256
|
+
})]
|
|
257
|
+
}) : rawLabel;
|
|
258
|
+
return (0, _jsxRuntime.jsx)(_FormField.FormField, {
|
|
256
259
|
id: this.id,
|
|
257
260
|
label: label,
|
|
258
261
|
messagesId: this._messagesId,
|
|
@@ -262,20 +265,25 @@ let TextInput = exports.TextInput = (_dec = (0, _withDeterministicId.withDetermi
|
|
|
262
265
|
inputContainerRef: inputContainerRef,
|
|
263
266
|
layout: this.props.layout,
|
|
264
267
|
elementRef: this.handleRef,
|
|
265
|
-
margin: this.props.margin
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
268
|
+
margin: this.props.margin,
|
|
269
|
+
children: (0, _jsxRuntime.jsx)("span", {
|
|
270
|
+
css: styles === null || styles === void 0 ? void 0 : styles.facade,
|
|
271
|
+
children: renderBeforeOrAfter ? (0, _jsxRuntime.jsxs)("span", {
|
|
272
|
+
css: styles === null || styles === void 0 ? void 0 : styles.layout,
|
|
273
|
+
children: [beforeElement, (0, _jsxRuntime.jsxs)("span", {
|
|
274
|
+
css: styles === null || styles === void 0 ? void 0 : styles.inputLayout,
|
|
275
|
+
children: [this.renderInput(), afterElement && (0, _jsxRuntime.jsx)("span", {
|
|
276
|
+
css: styles === null || styles === void 0 ? void 0 : styles.afterElement,
|
|
277
|
+
ref: e => {
|
|
278
|
+
this._afterElement = e;
|
|
279
|
+
},
|
|
280
|
+
children: afterElement
|
|
281
|
+
})]
|
|
282
|
+
})]
|
|
283
|
+
}) : (/* If no prepended or appended content, don't render Flex layout */
|
|
284
|
+
this.renderInput())
|
|
285
|
+
})
|
|
286
|
+
});
|
|
279
287
|
}
|
|
280
288
|
}, _TextInput.displayName = "TextInput", _TextInput.componentId = 'TextInput', _TextInput.allowedProps = _props.allowedProps, _TextInput.propTypes = _props.propTypes, _TextInput.defaultProps = {
|
|
281
289
|
type: 'text',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-text-input",
|
|
3
|
-
"version": "10.16.1
|
|
3
|
+
"version": "10.16.1",
|
|
4
4
|
"description": "A styled HTML text input component.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,12 +23,12 @@
|
|
|
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
|
|
28
|
-
"@instructure/ui-badge": "10.16.1
|
|
29
|
-
"@instructure/ui-color-utils": "10.16.1
|
|
30
|
-
"@instructure/ui-test-utils": "10.16.1
|
|
31
|
-
"@instructure/ui-themes": "10.16.1
|
|
26
|
+
"@instructure/ui-axe-check": "10.16.1",
|
|
27
|
+
"@instructure/ui-babel-preset": "10.16.1",
|
|
28
|
+
"@instructure/ui-badge": "10.16.1",
|
|
29
|
+
"@instructure/ui-color-utils": "10.16.1",
|
|
30
|
+
"@instructure/ui-test-utils": "10.16.1",
|
|
31
|
+
"@instructure/ui-themes": "10.16.1",
|
|
32
32
|
"@testing-library/jest-dom": "^6.6.3",
|
|
33
33
|
"@testing-library/react": "^16.0.1",
|
|
34
34
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -36,15 +36,15 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@babel/runtime": "^7.26.0",
|
|
39
|
-
"@instructure/emotion": "10.16.1
|
|
40
|
-
"@instructure/shared-types": "10.16.1
|
|
41
|
-
"@instructure/ui-dom-utils": "10.16.1
|
|
42
|
-
"@instructure/ui-form-field": "10.16.1
|
|
43
|
-
"@instructure/ui-icons": "10.16.1
|
|
44
|
-
"@instructure/ui-prop-types": "10.16.1
|
|
45
|
-
"@instructure/ui-react-utils": "10.16.1
|
|
46
|
-
"@instructure/ui-tag": "10.16.1
|
|
47
|
-
"@instructure/ui-testable": "10.16.1
|
|
39
|
+
"@instructure/emotion": "10.16.1",
|
|
40
|
+
"@instructure/shared-types": "10.16.1",
|
|
41
|
+
"@instructure/ui-dom-utils": "10.16.1",
|
|
42
|
+
"@instructure/ui-form-field": "10.16.1",
|
|
43
|
+
"@instructure/ui-icons": "10.16.1",
|
|
44
|
+
"@instructure/ui-prop-types": "10.16.1",
|
|
45
|
+
"@instructure/ui-react-utils": "10.16.1",
|
|
46
|
+
"@instructure/ui-tag": "10.16.1",
|
|
47
|
+
"@instructure/ui-testable": "10.16.1",
|
|
48
48
|
"prop-types": "^15.8.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
package/src/TextInput/index.tsx
CHANGED
|
@@ -22,8 +22,7 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
import React, { Component } from 'react'
|
|
25
|
+
import { Fragment, Component } from 'react'
|
|
27
26
|
|
|
28
27
|
import {
|
|
29
28
|
callRenderProp,
|
|
@@ -34,7 +33,7 @@ import {
|
|
|
34
33
|
import { isActiveElement, addEventListener } from '@instructure/ui-dom-utils'
|
|
35
34
|
import { FormField } from '@instructure/ui-form-field'
|
|
36
35
|
import { testable } from '@instructure/ui-testable'
|
|
37
|
-
import { withStyle
|
|
36
|
+
import { withStyle } from '@instructure/emotion'
|
|
38
37
|
import { hasVisibleChildren } from '@instructure/ui-a11y-utils'
|
|
39
38
|
|
|
40
39
|
import generateStyle from './styles'
|
|
@@ -320,7 +319,7 @@ class TextInput extends Component<TextInputProps, TextInputState> {
|
|
|
320
319
|
|
|
321
320
|
const rawLabel = callRenderProp(renderLabel)
|
|
322
321
|
const label = hasVisibleChildren(rawLabel) ? (
|
|
323
|
-
<
|
|
322
|
+
<Fragment>
|
|
324
323
|
{rawLabel}
|
|
325
324
|
{isRequired && (
|
|
326
325
|
<span
|
|
@@ -331,7 +330,7 @@ class TextInput extends Component<TextInputProps, TextInputState> {
|
|
|
331
330
|
*
|
|
332
331
|
</span>
|
|
333
332
|
)}
|
|
334
|
-
</
|
|
333
|
+
</Fragment>
|
|
335
334
|
) : (
|
|
336
335
|
rawLabel
|
|
337
336
|
)
|