@instructure/ui-form-field 10.11.1-snapshot-18 → 10.12.1-snapshot-0
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 +16 -2
- package/es/FormField/index.js +2 -2
- package/es/FormField/props.js +3 -2
- package/es/FormFieldGroup/__new-tests__/FormFieldGroup.test.js +4 -4
- package/es/FormFieldGroup/index.js +18 -4
- package/es/FormFieldLayout/__new-tests__/FormFieldLayout.test.js +10 -8
- package/es/FormFieldLayout/index.js +76 -55
- package/es/FormFieldLayout/props.js +3 -2
- package/es/FormFieldLayout/styles.js +113 -10
- package/es/{FormFieldLabel → FormFieldLayout}/theme.js +6 -1
- package/es/FormFieldMessages/props.js +3 -2
- package/es/FormFieldMessages/styles.js +5 -3
- package/es/FormPropTypes.js +6 -0
- package/es/index.js +0 -1
- package/lib/FormField/index.js +2 -2
- package/lib/FormField/props.js +3 -2
- package/lib/FormFieldGroup/__new-tests__/FormFieldGroup.test.js +4 -4
- package/lib/FormFieldGroup/index.js +18 -4
- package/lib/FormFieldLayout/__new-tests__/FormFieldLayout.test.js +9 -7
- package/lib/FormFieldLayout/index.js +74 -55
- package/lib/FormFieldLayout/props.js +3 -2
- package/lib/FormFieldLayout/styles.js +113 -10
- package/lib/{FormFieldLabel → FormFieldLayout}/theme.js +6 -1
- package/lib/FormFieldMessages/props.js +3 -2
- package/lib/FormFieldMessages/styles.js +5 -3
- package/lib/FormPropTypes.js +6 -0
- package/lib/index.js +0 -7
- package/package.json +15 -15
- package/src/FormField/README.md +31 -3
- package/src/FormField/index.tsx +1 -1
- package/src/FormField/props.ts +10 -2
- package/src/FormFieldGroup/__new-tests__/FormFieldGroup.test.tsx +4 -6
- package/src/FormFieldGroup/index.tsx +41 -6
- package/src/FormFieldLayout/__new-tests__/FormFieldLayout.test.tsx +6 -8
- package/src/FormFieldLayout/index.tsx +80 -93
- package/src/FormFieldLayout/props.ts +42 -5
- package/src/FormFieldLayout/styles.ts +130 -13
- package/src/{FormFieldLabel → FormFieldLayout}/theme.ts +9 -6
- package/src/FormFieldMessages/props.ts +8 -2
- package/src/FormFieldMessages/styles.ts +5 -4
- package/src/FormPropTypes.ts +4 -0
- package/src/index.ts +0 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/FormField/props.d.ts +5 -0
- package/types/FormField/props.d.ts.map +1 -1
- package/types/FormFieldGroup/index.d.ts +1 -0
- package/types/FormFieldGroup/index.d.ts.map +1 -1
- package/types/FormFieldLayout/index.d.ts +8 -7
- package/types/FormFieldLayout/index.d.ts.map +1 -1
- package/types/FormFieldLayout/props.d.ts +32 -4
- package/types/FormFieldLayout/props.d.ts.map +1 -1
- package/types/FormFieldLayout/styles.d.ts +4 -3
- package/types/FormFieldLayout/styles.d.ts.map +1 -1
- package/types/{FormFieldLabel → FormFieldLayout}/theme.d.ts +2 -2
- package/types/FormFieldLayout/theme.d.ts.map +1 -0
- package/types/FormFieldMessages/index.d.ts +8 -2
- package/types/FormFieldMessages/index.d.ts.map +1 -1
- package/types/FormFieldMessages/props.d.ts +5 -0
- package/types/FormFieldMessages/props.d.ts.map +1 -1
- package/types/FormFieldMessages/styles.d.ts +2 -3
- package/types/FormFieldMessages/styles.d.ts.map +1 -1
- package/types/FormPropTypes.d.ts +3 -0
- package/types/FormPropTypes.d.ts.map +1 -1
- package/types/index.d.ts +0 -2
- package/types/index.d.ts.map +1 -1
- package/es/FormFieldLabel/__new-tests__/FormFieldLabel.test.js +0 -66
- package/es/FormFieldLabel/index.js +0 -79
- package/es/FormFieldLabel/props.js +0 -31
- package/es/FormFieldLabel/styles.js +0 -62
- package/lib/FormFieldLabel/__new-tests__/FormFieldLabel.test.js +0 -68
- package/lib/FormFieldLabel/index.js +0 -85
- package/lib/FormFieldLabel/props.js +0 -37
- package/lib/FormFieldLabel/styles.js +0 -68
- package/src/FormFieldLabel/__new-tests__/FormFieldLabel.test.tsx +0 -79
- package/src/FormFieldLabel/index.tsx +0 -95
- package/src/FormFieldLabel/props.ts +0 -58
- package/src/FormFieldLabel/styles.ts +0 -74
- package/types/FormFieldLabel/__new-tests__/FormFieldLabel.test.d.ts +0 -2
- package/types/FormFieldLabel/__new-tests__/FormFieldLabel.test.d.ts.map +0 -1
- package/types/FormFieldLabel/index.d.ts +0 -42
- package/types/FormFieldLabel/index.d.ts.map +0 -1
- package/types/FormFieldLabel/props.d.ts +0 -15
- package/types/FormFieldLabel/props.d.ts.map +0 -1
- package/types/FormFieldLabel/styles.d.ts +0 -15
- package/types/FormFieldLabel/styles.d.ts.map +0 -1
- package/types/FormFieldLabel/theme.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,23 @@
|
|
|
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.
|
|
6
|
+
## [10.12.1-snapshot-0](https://github.com/instructure/instructure-ui/compare/v10.12.0...v10.12.1-snapshot-0) (2025-02-26)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **many:** fix form label not read by NVDA in hover mode and other layout issues ([ef77281](https://github.com/instructure/instructure-ui/commit/ef77281890511e8eea794196445d3ef2454537ba))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [10.12.0](https://github.com/instructure/instructure-ui/compare/v10.11.0...v10.12.0) (2025-02-24)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **many:** introduce new spacing tokens; add margin prop for more components ([048c902](https://github.com/instructure/instructure-ui/commit/048c902406c00611cd117fb2fb8164a6eba62fb8))
|
|
9
23
|
|
|
10
24
|
|
|
11
25
|
|
package/es/FormField/index.js
CHANGED
package/es/FormField/props.js
CHANGED
|
@@ -36,7 +36,8 @@ const propTypes = {
|
|
|
36
36
|
vAlign: PropTypes.oneOf(['top', 'middle', 'bottom']),
|
|
37
37
|
width: PropTypes.string,
|
|
38
38
|
inputContainerRef: PropTypes.func,
|
|
39
|
-
elementRef: PropTypes.func
|
|
39
|
+
elementRef: PropTypes.func,
|
|
40
|
+
margin: PropTypes.string
|
|
40
41
|
};
|
|
41
|
-
const allowedProps = ['label', 'id', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'vAlign', 'width', 'inputContainerRef', 'elementRef'];
|
|
42
|
+
const allowedProps = ['label', 'id', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'vAlign', 'width', 'inputContainerRef', 'elementRef', 'margin'];
|
|
42
43
|
export { propTypes, allowedProps };
|
|
@@ -46,7 +46,7 @@ describe('<FormFieldGroup />', () => {
|
|
|
46
46
|
description: "Please enter your full name"
|
|
47
47
|
}, /*#__PURE__*/React.createElement("label", null, "First: ", /*#__PURE__*/React.createElement("input", null)), /*#__PURE__*/React.createElement("label", null, "Middle: ", /*#__PURE__*/React.createElement("input", null)), /*#__PURE__*/React.createElement("label", null, "Last: ", /*#__PURE__*/React.createElement("input", null))))),
|
|
48
48
|
container = _render.container;
|
|
49
|
-
const formFieldGroup = container.querySelector("
|
|
49
|
+
const formFieldGroup = container.querySelector("span[class$='-formFieldLayout__label']");
|
|
50
50
|
const firstNameInput = screen.getByLabelText('First:');
|
|
51
51
|
const middleNameInput = screen.getByLabelText('Middle:');
|
|
52
52
|
const lastNameInput = screen.getByLabelText('Last:');
|
|
@@ -64,7 +64,7 @@ describe('<FormFieldGroup />', () => {
|
|
|
64
64
|
description: "Please enter your full name"
|
|
65
65
|
}, children)),
|
|
66
66
|
container = _render2.container;
|
|
67
|
-
const formFieldGroup = container.querySelector(
|
|
67
|
+
const formFieldGroup = container.querySelector('label');
|
|
68
68
|
expect(formFieldGroup).toBeInTheDocument();
|
|
69
69
|
});
|
|
70
70
|
it('links the messages to the fieldset via aria-describedby', () => {
|
|
@@ -86,13 +86,13 @@ describe('<FormFieldGroup />', () => {
|
|
|
86
86
|
expect(message).toHaveTextContent('Invalid name');
|
|
87
87
|
expect(message).toHaveAttribute('id', messagesId);
|
|
88
88
|
});
|
|
89
|
-
it('displays description message inside the
|
|
89
|
+
it('displays description message inside the label', () => {
|
|
90
90
|
const description = 'Please enter your full name';
|
|
91
91
|
const _render4 = render(/*#__PURE__*/React.createElement(FormFieldGroup, {
|
|
92
92
|
description: description
|
|
93
93
|
}, _label5 || (_label5 = /*#__PURE__*/React.createElement("label", null, "First: ", /*#__PURE__*/React.createElement("input", null))), _label6 || (_label6 = /*#__PURE__*/React.createElement("label", null, "Middle: ", /*#__PURE__*/React.createElement("input", null))), _label7 || (_label7 = /*#__PURE__*/React.createElement("label", null, "Last: ", /*#__PURE__*/React.createElement("input", null))))),
|
|
94
94
|
container = _render4.container;
|
|
95
|
-
const legend = container.querySelector("
|
|
95
|
+
const legend = container.querySelector("span[class$='-formFieldLayout__label']");
|
|
96
96
|
expect(legend).toBeInTheDocument();
|
|
97
97
|
expect(legend).toHaveTextContent(description);
|
|
98
98
|
});
|
|
@@ -60,13 +60,17 @@ let FormFieldGroup = (_dec = withStyle(generateStyle, generateComponentTheme), _
|
|
|
60
60
|
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStylesVariables);
|
|
61
61
|
}
|
|
62
62
|
get makeStylesVariables() {
|
|
63
|
+
// new form errors dont need borders
|
|
64
|
+
const oldInvalid = !!this.props.messages && this.props.messages.findIndex(message => {
|
|
65
|
+
return message.type === 'error';
|
|
66
|
+
}) >= 0;
|
|
63
67
|
return {
|
|
64
|
-
invalid:
|
|
68
|
+
invalid: oldInvalid
|
|
65
69
|
};
|
|
66
70
|
}
|
|
67
71
|
get invalid() {
|
|
68
72
|
return !!this.props.messages && this.props.messages.findIndex(message => {
|
|
69
|
-
return message.type === 'error';
|
|
73
|
+
return message.type === 'error' || message.type === 'newError';
|
|
70
74
|
}) >= 0;
|
|
71
75
|
}
|
|
72
76
|
renderColumns() {
|
|
@@ -98,12 +102,21 @@ let FormFieldGroup = (_dec = withStyle(generateStyle, generateComponentTheme), _
|
|
|
98
102
|
makeStyles = _this$props3.makeStyles,
|
|
99
103
|
isGroup = _this$props3.isGroup,
|
|
100
104
|
props = _objectWithoutProperties(_this$props3, _excluded);
|
|
105
|
+
// This is quite ugly, but according to ARIA spec the `aria-invalid` prop
|
|
106
|
+
// can only be used with certain roles see
|
|
107
|
+
// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-invalid#associated_roles
|
|
108
|
+
// `aria-invalid` is put on in FormFieldLayout because the error message
|
|
109
|
+
// DOM part gets there its ID.
|
|
110
|
+
let ariaInvalid = void 0;
|
|
111
|
+
if (this.props.role && this.invalid && ['application', 'checkbox', 'combobox', 'gridcell', 'listbox', 'radiogroup', 'slider', 'spinbutton', 'textbox', 'tree', 'columnheader', 'rowheader', 'searchbox', 'switch', 'treegrid'].includes(this.props.role)) {
|
|
112
|
+
ariaInvalid = 'true';
|
|
113
|
+
}
|
|
101
114
|
return jsx(FormFieldLayout, Object.assign({}, omitProps(props, FormFieldGroup.allowedProps), pickProps(props, FormFieldLayout.allowedProps), {
|
|
102
115
|
vAlign: props.vAlign,
|
|
103
116
|
layout: props.layout === 'inline' ? 'inline' : 'stacked',
|
|
104
117
|
label: props.description,
|
|
105
118
|
"aria-disabled": props.disabled ? 'true' : void 0,
|
|
106
|
-
"aria-invalid":
|
|
119
|
+
"aria-invalid": ariaInvalid,
|
|
107
120
|
elementRef: this.handleRef,
|
|
108
121
|
isGroup: isGroup
|
|
109
122
|
}), this.renderFields());
|
|
@@ -113,7 +126,8 @@ let FormFieldGroup = (_dec = withStyle(generateStyle, generateComponentTheme), _
|
|
|
113
126
|
disabled: false,
|
|
114
127
|
rowSpacing: 'medium',
|
|
115
128
|
colSpacing: 'small',
|
|
116
|
-
vAlign: 'middle'
|
|
129
|
+
vAlign: 'middle',
|
|
130
|
+
isGroup: true
|
|
117
131
|
}, _FormFieldGroup)) || _class);
|
|
118
132
|
export default FormFieldGroup;
|
|
119
133
|
export { FormFieldGroup };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _FormFieldLayout, _FormFieldLayout2
|
|
1
|
+
var _FormFieldLayout, _FormFieldLayout2;
|
|
2
2
|
/*
|
|
3
3
|
* The MIT License (MIT)
|
|
4
4
|
*
|
|
@@ -24,7 +24,7 @@ var _FormFieldLayout, _FormFieldLayout2, _input;
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import React from 'react';
|
|
27
|
-
import { render
|
|
27
|
+
import { render } from '@testing-library/react';
|
|
28
28
|
import { vi } from 'vitest';
|
|
29
29
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
30
30
|
import '@testing-library/jest-dom';
|
|
@@ -47,7 +47,7 @@ describe('<FormFieldLayout />', () => {
|
|
|
47
47
|
}))),
|
|
48
48
|
container = _render.container;
|
|
49
49
|
const formFieldLayout = container.querySelector("label[class$='-formFieldLayout']");
|
|
50
|
-
const formFieldLabel = container.querySelector("span[class$='-
|
|
50
|
+
const formFieldLabel = container.querySelector("span[class$='-formFieldLayout__label']");
|
|
51
51
|
expect(formFieldLayout).toBeInTheDocument();
|
|
52
52
|
expect(formFieldLabel).toBeInTheDocument();
|
|
53
53
|
expect(formFieldLabel).toHaveTextContent('Username');
|
|
@@ -62,13 +62,15 @@ describe('<FormFieldLayout />', () => {
|
|
|
62
62
|
});
|
|
63
63
|
it('should provide a ref to the input container', () => {
|
|
64
64
|
const inputContainerRef = vi.fn();
|
|
65
|
+
const ref = /*#__PURE__*/React.createRef();
|
|
65
66
|
render(/*#__PURE__*/React.createElement(FormFieldLayout, {
|
|
66
67
|
label: "Username",
|
|
67
68
|
inputContainerRef: inputContainerRef
|
|
68
|
-
},
|
|
69
|
-
type: "text"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
expect(
|
|
69
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
70
|
+
type: "text",
|
|
71
|
+
ref: ref
|
|
72
|
+
})));
|
|
73
|
+
expect(ref.current).toBeInstanceOf(HTMLInputElement);
|
|
74
|
+
expect(inputContainerRef).toHaveBeenCalledWith(ref.current.parentElement);
|
|
73
75
|
});
|
|
74
76
|
});
|
|
@@ -28,23 +28,23 @@ var _dec, _dec2, _class, _FormFieldLayout;
|
|
|
28
28
|
/** @jsx jsx */
|
|
29
29
|
import { Component } from 'react';
|
|
30
30
|
import { hasVisibleChildren } from '@instructure/ui-a11y-utils';
|
|
31
|
-
import {
|
|
32
|
-
import { Grid } from '@instructure/ui-grid';
|
|
33
|
-
import { omitProps, pickProps, getElementType, withDeterministicId } from '@instructure/ui-react-utils';
|
|
31
|
+
import { omitProps, getElementType, withDeterministicId } from '@instructure/ui-react-utils';
|
|
34
32
|
import { withStyle, jsx } from '@instructure/emotion';
|
|
35
|
-
import { FormFieldLabel } from '../FormFieldLabel';
|
|
36
33
|
import { FormFieldMessages } from '../FormFieldMessages';
|
|
37
34
|
import generateStyle from './styles';
|
|
38
35
|
import { propTypes, allowedProps } from './props';
|
|
36
|
+
import generateComponentTheme from './theme';
|
|
37
|
+
|
|
39
38
|
/**
|
|
40
39
|
---
|
|
41
40
|
parent: FormField
|
|
42
41
|
---
|
|
43
42
|
**/
|
|
44
|
-
let FormFieldLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle,
|
|
43
|
+
let FormFieldLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec(_class = _dec2(_class = (_FormFieldLayout = class FormFieldLayout extends Component {
|
|
45
44
|
constructor(props) {
|
|
46
45
|
super(props);
|
|
47
46
|
this._messagesId = void 0;
|
|
47
|
+
this._labelId = void 0;
|
|
48
48
|
this.ref = null;
|
|
49
49
|
this.handleRef = el => {
|
|
50
50
|
const elementRef = this.props.elementRef;
|
|
@@ -53,69 +53,96 @@ let FormFieldLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateS
|
|
|
53
53
|
elementRef(el);
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
+
this.makeStyleProps = () => {
|
|
57
|
+
var _this$props$messages;
|
|
58
|
+
const hasNewErrorMsgAndIsGroup = !!((_this$props$messages = this.props.messages) !== null && _this$props$messages !== void 0 && _this$props$messages.find(m => m.type === 'newError')) && !!this.props.isGroup;
|
|
59
|
+
return {
|
|
60
|
+
hasMessages: this.hasMessages,
|
|
61
|
+
hasVisibleLabel: this.hasVisibleLabel,
|
|
62
|
+
// if true render error message above the controls (and below the label)
|
|
63
|
+
hasNewErrorMsgAndIsGroup: hasNewErrorMsgAndIsGroup
|
|
64
|
+
};
|
|
65
|
+
};
|
|
56
66
|
this.handleInputContainerRef = node => {
|
|
57
67
|
if (typeof this.props.inputContainerRef === 'function') {
|
|
58
68
|
this.props.inputContainerRef(node);
|
|
59
69
|
}
|
|
60
70
|
};
|
|
61
71
|
this._messagesId = props.messagesId || props.deterministicId();
|
|
72
|
+
this._labelId = props.deterministicId('FormField-Label');
|
|
62
73
|
}
|
|
63
74
|
componentDidMount() {
|
|
64
75
|
var _this$props$makeStyle, _this$props;
|
|
65
|
-
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
76
|
+
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.makeStyleProps());
|
|
66
77
|
}
|
|
67
78
|
componentDidUpdate() {
|
|
68
79
|
var _this$props$makeStyle2, _this$props2;
|
|
69
|
-
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
80
|
+
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStyleProps());
|
|
70
81
|
}
|
|
71
82
|
get hasVisibleLabel() {
|
|
72
|
-
return this.props.label
|
|
83
|
+
return this.props.label ? hasVisibleChildren(this.props.label) : false;
|
|
73
84
|
}
|
|
74
85
|
get hasMessages() {
|
|
75
|
-
|
|
86
|
+
if (!this.props.messages || this.props.messages.length == 0) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
for (const msg of this.props.messages) {
|
|
90
|
+
if (msg.text) {
|
|
91
|
+
if (typeof msg.text === 'string') {
|
|
92
|
+
return msg.text.length > 0;
|
|
93
|
+
}
|
|
94
|
+
// this is more complicated (e.g. an array, a React component,...)
|
|
95
|
+
// but we don't try to optimize here for these cases
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
76
100
|
}
|
|
77
101
|
get elementType() {
|
|
78
102
|
return getElementType(FormFieldLayout, this.props);
|
|
79
103
|
}
|
|
80
|
-
get inlineContainerAndLabel() {
|
|
81
|
-
// Return if both the component container and label will display inline
|
|
82
|
-
return this.props.inline && this.props.layout === 'inline';
|
|
83
|
-
}
|
|
84
104
|
renderLabel() {
|
|
85
105
|
if (this.hasVisibleLabel) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
var _this$props$styles2;
|
|
107
|
+
if (this.elementType == 'fieldset') {
|
|
108
|
+
var _this$props$styles;
|
|
109
|
+
// `legend` has some special built in CSS, this can only be reset
|
|
110
|
+
// this way https://stackoverflow.com/a/65866981/319473
|
|
111
|
+
return jsx("legend", {
|
|
112
|
+
style: {
|
|
113
|
+
display: 'contents'
|
|
114
|
+
}
|
|
115
|
+
}, jsx("span", {
|
|
116
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.formFieldLabel
|
|
117
|
+
}, this.props.label));
|
|
118
|
+
}
|
|
119
|
+
return jsx("span", {
|
|
120
|
+
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.formFieldLabel
|
|
121
|
+
}, this.props.label);
|
|
122
|
+
} else if (this.props.label) {
|
|
123
|
+
if (this.elementType == 'fieldset') {
|
|
124
|
+
return jsx("legend", {
|
|
125
|
+
id: this._labelId,
|
|
126
|
+
style: {
|
|
127
|
+
display: 'contents'
|
|
128
|
+
}
|
|
129
|
+
}, this.props.label);
|
|
130
|
+
}
|
|
131
|
+
// needs to be wrapped because it needs an `id`
|
|
132
|
+
return jsx("div", {
|
|
133
|
+
id: this._labelId
|
|
134
|
+
}, this.props.label);
|
|
135
|
+
} else return null;
|
|
107
136
|
}
|
|
108
137
|
renderVisibleMessages() {
|
|
109
|
-
return this.hasMessages ? jsx(
|
|
110
|
-
offset: this.inlineContainerAndLabel ? void 0 : 3,
|
|
111
|
-
textAlign: this.inlineContainerAndLabel ? 'end' : void 0
|
|
112
|
-
}, jsx(FormFieldMessages, {
|
|
138
|
+
return this.hasMessages ? jsx(FormFieldMessages, {
|
|
113
139
|
id: this._messagesId,
|
|
114
|
-
messages: this.props.messages
|
|
115
|
-
|
|
140
|
+
messages: this.props.messages,
|
|
141
|
+
gridArea: "messages"
|
|
142
|
+
}) : null;
|
|
116
143
|
}
|
|
117
144
|
render() {
|
|
118
|
-
//
|
|
145
|
+
// Should be `<label>` if it's a FormField, fieldset if it's a group
|
|
119
146
|
const ElementType = this.elementType;
|
|
120
147
|
const _this$props3 = this.props,
|
|
121
148
|
makeStyles = _this$props3.makeStyles,
|
|
@@ -124,26 +151,20 @@ let FormFieldLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateS
|
|
|
124
151
|
isGroup = _this$props3.isGroup,
|
|
125
152
|
props = _objectWithoutProperties(_this$props3, _excluded);
|
|
126
153
|
const width = props.width,
|
|
127
|
-
layout = props.layout,
|
|
128
154
|
children = props.children;
|
|
129
|
-
const
|
|
130
|
-
return jsx(ElementType, Object.assign({}, omitProps(props, [...FormFieldLayout.allowedProps
|
|
155
|
+
const hasNewErrorMsgAndIsGroup = !!(messages !== null && messages !== void 0 && messages.find(m => m.type === 'newError')) && isGroup;
|
|
156
|
+
return jsx(ElementType, Object.assign({}, omitProps(props, [...FormFieldLayout.allowedProps]), {
|
|
131
157
|
css: styles === null || styles === void 0 ? void 0 : styles.formFieldLayout,
|
|
158
|
+
"aria-describedby": this.hasMessages ? this._messagesId : void 0,
|
|
159
|
+
"aria-errormessage": this.props['aria-invalid'] ? this._messagesId : void 0,
|
|
132
160
|
style: {
|
|
133
161
|
width
|
|
134
162
|
},
|
|
135
|
-
"aria-describedby": this.hasMessages ? this._messagesId : void 0,
|
|
136
163
|
ref: this.handleRef
|
|
137
|
-
}), this.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}, pickProps(props, Grid.allowedProps)), jsx(Grid.Row, null, this.renderLabel(), jsx(Grid.Col, {
|
|
142
|
-
width: this.inlineContainerAndLabel ? 'auto' : void 0,
|
|
143
|
-
elementRef: this.handleInputContainerRef
|
|
144
|
-
}, hasNewErrorMsg && jsx("div", {
|
|
145
|
-
css: styles === null || styles === void 0 ? void 0 : styles.groupErrorMessage
|
|
146
|
-
}, this.renderVisibleMessages()), children)), !hasNewErrorMsg && this.renderVisibleMessages()));
|
|
164
|
+
}), this.renderLabel(), hasNewErrorMsgAndIsGroup && this.renderVisibleMessages(), jsx("span", {
|
|
165
|
+
css: styles === null || styles === void 0 ? void 0 : styles.formFieldChildren,
|
|
166
|
+
ref: this.handleInputContainerRef
|
|
167
|
+
}, children), !hasNewErrorMsgAndIsGroup && this.renderVisibleMessages());
|
|
147
168
|
}
|
|
148
169
|
}, _FormFieldLayout.displayName = "FormFieldLayout", _FormFieldLayout.componentId = 'FormFieldLayout', _FormFieldLayout.propTypes = propTypes, _FormFieldLayout.allowedProps = allowedProps, _FormFieldLayout.defaultProps = {
|
|
149
170
|
inline: false,
|
|
@@ -38,9 +38,10 @@ const propTypes = {
|
|
|
38
38
|
width: PropTypes.string,
|
|
39
39
|
inputContainerRef: PropTypes.func,
|
|
40
40
|
elementRef: PropTypes.func,
|
|
41
|
-
isGroup: PropTypes.bool
|
|
41
|
+
isGroup: PropTypes.bool,
|
|
42
|
+
margin: PropTypes.string
|
|
42
43
|
};
|
|
43
|
-
const allowedProps = ['label', 'id', 'as', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'width', 'inputContainerRef', 'elementRef'
|
|
44
|
+
const allowedProps = ['label', 'id', 'as', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'width', 'inputContainerRef', 'elementRef', 'margin'
|
|
44
45
|
|
|
45
46
|
// added vAlign because FormField and FormFieldGroup passes it, but not adding
|
|
46
47
|
// it to allowedProps to prevent it from getting passed through accidentally
|
|
@@ -22,6 +22,32 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
+
import { mapSpacingToShorthand } from '@instructure/emotion';
|
|
26
|
+
const generateGridLayout = (isInlineLayout, hasNewErrorMsgAndIsGroup, hasVisibleLabel, hasMessages) => {
|
|
27
|
+
if (isInlineLayout) {
|
|
28
|
+
if (hasNewErrorMsgAndIsGroup) {
|
|
29
|
+
if (hasMessages) {
|
|
30
|
+
return `${hasVisibleLabel ? ' "label messages"' : '. messages'}
|
|
31
|
+
". controls"`;
|
|
32
|
+
} else {
|
|
33
|
+
return `${hasVisibleLabel ? ' "label controls"' : '. controls'}`;
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
return `${hasVisibleLabel ? ' "label controls"' : '. controls'}
|
|
37
|
+
${hasMessages ? ' ". messages"' : ''}`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// stacked layout -- in this case we could use a simple `Flex`
|
|
41
|
+
if (hasNewErrorMsgAndIsGroup) {
|
|
42
|
+
return `${hasVisibleLabel ? ' "label"' : ''}
|
|
43
|
+
${hasMessages ? ' "messages"' : ''}
|
|
44
|
+
"controls"`;
|
|
45
|
+
} else {
|
|
46
|
+
return `${hasVisibleLabel ? ' "label"' : ''}
|
|
47
|
+
"controls"
|
|
48
|
+
${hasMessages ? ' "messages"' : ''}`;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
25
51
|
/**
|
|
26
52
|
* ---
|
|
27
53
|
* private: true
|
|
@@ -29,32 +55,109 @@
|
|
|
29
55
|
* Generates the style object from the theme and provided additional information
|
|
30
56
|
* @param {Object} componentTheme The theme variable object.
|
|
31
57
|
* @param {Object} props the props of the component, the style is applied to
|
|
32
|
-
* @param {Object}
|
|
58
|
+
* @param {Object} styleProps
|
|
33
59
|
* @return {Object} The final style object, which will be used in the component
|
|
34
60
|
*/
|
|
35
|
-
const generateStyle = (
|
|
36
|
-
const inline = props.inline
|
|
61
|
+
const generateStyle = (componentTheme, props, styleProps) => {
|
|
62
|
+
const inline = props.inline,
|
|
63
|
+
layout = props.layout,
|
|
64
|
+
vAlign = props.vAlign,
|
|
65
|
+
labelAlign = props.labelAlign,
|
|
66
|
+
margin = props.margin;
|
|
67
|
+
const hasMessages = styleProps.hasMessages,
|
|
68
|
+
hasVisibleLabel = styleProps.hasVisibleLabel,
|
|
69
|
+
hasNewErrorMsgAndIsGroup = styleProps.hasNewErrorMsgAndIsGroup;
|
|
70
|
+
const cssMargin = mapSpacingToShorthand(margin, componentTheme.spacing);
|
|
71
|
+
const isInlineLayout = layout === 'inline';
|
|
72
|
+
// This is quite ugly, we should simplify it
|
|
73
|
+
const gridTemplateAreas = generateGridLayout(isInlineLayout, hasNewErrorMsgAndIsGroup, hasVisibleLabel, hasMessages);
|
|
74
|
+
let gridTemplateColumns = '100%'; // stacked layout
|
|
75
|
+
if (isInlineLayout) {
|
|
76
|
+
gridTemplateColumns = '1fr 3fr';
|
|
77
|
+
if (inline) {
|
|
78
|
+
gridTemplateColumns = 'auto 3fr';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const labelStyles = {
|
|
82
|
+
all: 'initial',
|
|
83
|
+
display: 'block',
|
|
84
|
+
gridArea: 'label',
|
|
85
|
+
color: componentTheme.color,
|
|
86
|
+
fontFamily: componentTheme.fontFamily,
|
|
87
|
+
fontWeight: componentTheme.fontWeight,
|
|
88
|
+
fontSize: componentTheme.fontSize,
|
|
89
|
+
lineHeight: componentTheme.lineHeight,
|
|
90
|
+
margin: '0 0 0.75rem 0',
|
|
91
|
+
...(isInlineLayout && {
|
|
92
|
+
// when inline add a small padding between the label and the control
|
|
93
|
+
paddingRight: componentTheme.inlinePadding,
|
|
94
|
+
// and use the horizontal alignment prop
|
|
95
|
+
[`@media screen and (min-width: ${componentTheme.stackedOrInlineBreakpoint})`]: {
|
|
96
|
+
textAlign: labelAlign
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
};
|
|
100
|
+
let alignItems = 'start';
|
|
101
|
+
if (vAlign == 'top') {
|
|
102
|
+
alignItems = 'start';
|
|
103
|
+
} else if (vAlign == 'middle') {
|
|
104
|
+
alignItems = 'center';
|
|
105
|
+
} else if (vAlign == 'bottom') {
|
|
106
|
+
alignItems = 'end';
|
|
107
|
+
}
|
|
37
108
|
return {
|
|
38
|
-
groupErrorMessage: {
|
|
39
|
-
margin: '0.5rem 0'
|
|
40
|
-
},
|
|
41
109
|
formFieldLayout: {
|
|
42
110
|
label: 'formFieldLayout',
|
|
43
111
|
all: 'initial',
|
|
44
112
|
border: '0',
|
|
45
113
|
padding: '0',
|
|
46
|
-
margin:
|
|
114
|
+
margin: cssMargin,
|
|
47
115
|
minWidth: '0',
|
|
48
116
|
direction: 'inherit',
|
|
49
117
|
textAlign: 'start',
|
|
50
118
|
opacity: 'inherit',
|
|
51
|
-
display: '
|
|
119
|
+
display: 'grid',
|
|
120
|
+
alignItems: alignItems,
|
|
121
|
+
verticalAlign: 'middle',
|
|
122
|
+
// removes margin in inline layouts
|
|
123
|
+
gridTemplateColumns: gridTemplateColumns,
|
|
124
|
+
gridTemplateAreas: gridTemplateAreas,
|
|
125
|
+
[`@media screen and (max-width: ${componentTheme.stackedOrInlineBreakpoint})`]: {
|
|
126
|
+
// for small screens use the stacked layout
|
|
127
|
+
gridTemplateColumns: '100%',
|
|
128
|
+
gridTemplateAreas: generateGridLayout(false, hasNewErrorMsgAndIsGroup, hasVisibleLabel, hasMessages)
|
|
129
|
+
},
|
|
130
|
+
columnGap: '0.375rem',
|
|
52
131
|
width: '100%',
|
|
53
132
|
...(inline && {
|
|
54
|
-
display: 'inline-
|
|
55
|
-
verticalAlign: 'middle',
|
|
133
|
+
display: 'inline-grid',
|
|
56
134
|
width: 'auto'
|
|
57
135
|
})
|
|
136
|
+
},
|
|
137
|
+
formFieldLabel: {
|
|
138
|
+
label: 'formFieldLayout__label',
|
|
139
|
+
...(hasVisibleLabel && {
|
|
140
|
+
...labelStyles,
|
|
141
|
+
// NOTE: needs separate groups for `:is()` and `:-webkit-any()` because of css selector group validation (see https://www.w3.org/TR/selectors-3/#grouping)
|
|
142
|
+
'&:is(label)': labelStyles,
|
|
143
|
+
'&:-webkit-any(label)': labelStyles
|
|
144
|
+
})
|
|
145
|
+
},
|
|
146
|
+
formFieldChildren: {
|
|
147
|
+
label: 'formFieldLayout__children',
|
|
148
|
+
gridArea: 'controls',
|
|
149
|
+
// add a small margin between the message and the controls
|
|
150
|
+
...(hasMessages && hasNewErrorMsgAndIsGroup && {
|
|
151
|
+
marginTop: '0.375rem'
|
|
152
|
+
}),
|
|
153
|
+
...(hasMessages && !hasNewErrorMsgAndIsGroup && {
|
|
154
|
+
marginBottom: '0.75rem'
|
|
155
|
+
}),
|
|
156
|
+
...(isInlineLayout && inline && {
|
|
157
|
+
[`@media screen and (min-width: ${componentTheme.stackedOrInlineBreakpoint})`]: {
|
|
158
|
+
justifySelf: 'start'
|
|
159
|
+
}
|
|
160
|
+
})
|
|
58
161
|
}
|
|
59
162
|
};
|
|
60
163
|
};
|
|
@@ -31,6 +31,8 @@ const generateComponentTheme = theme => {
|
|
|
31
31
|
var _colors$contrasts;
|
|
32
32
|
const colors = theme.colors,
|
|
33
33
|
typography = theme.typography,
|
|
34
|
+
spacing = theme.spacing,
|
|
35
|
+
breakpoints = theme.breakpoints,
|
|
34
36
|
themeName = theme.key;
|
|
35
37
|
const themeSpecificStyle = {
|
|
36
38
|
canvas: {
|
|
@@ -42,7 +44,10 @@ const generateComponentTheme = theme => {
|
|
|
42
44
|
fontFamily: typography === null || typography === void 0 ? void 0 : typography.fontFamily,
|
|
43
45
|
fontWeight: typography === null || typography === void 0 ? void 0 : typography.fontWeightBold,
|
|
44
46
|
fontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeMedium,
|
|
45
|
-
lineHeight: typography === null || typography === void 0 ? void 0 : typography.lineHeightFit
|
|
47
|
+
lineHeight: typography === null || typography === void 0 ? void 0 : typography.lineHeightFit,
|
|
48
|
+
inlinePadding: spacing === null || spacing === void 0 ? void 0 : spacing.xxSmall,
|
|
49
|
+
stackedOrInlineBreakpoint: breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.medium,
|
|
50
|
+
spacing: theme.spacing
|
|
46
51
|
};
|
|
47
52
|
return {
|
|
48
53
|
...componentVariables,
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
import PropTypes from 'prop-types';
|
|
26
26
|
import { FormPropTypes } from '../FormPropTypes';
|
|
27
27
|
const propTypes = {
|
|
28
|
-
messages: PropTypes.arrayOf(FormPropTypes.message)
|
|
28
|
+
messages: PropTypes.arrayOf(FormPropTypes.message),
|
|
29
|
+
gridArea: PropTypes.string
|
|
29
30
|
};
|
|
30
|
-
const allowedProps = ['messages'];
|
|
31
|
+
const allowedProps = ['messages', 'gridArea'];
|
|
31
32
|
export { propTypes, allowedProps };
|
|
@@ -29,16 +29,18 @@
|
|
|
29
29
|
* Generates the style object from the theme and provided additional information
|
|
30
30
|
* @param {Object} componentTheme The theme variable object.
|
|
31
31
|
* @param {Object} props the props of the component, the style is applied to
|
|
32
|
-
* @param {Object} state the state of the component, the style is applied to
|
|
33
32
|
* @return {Object} The final style object, which will be used in the component
|
|
34
33
|
*/
|
|
35
|
-
const generateStyle = componentTheme => {
|
|
34
|
+
const generateStyle = (componentTheme, props) => {
|
|
36
35
|
return {
|
|
37
36
|
formFieldMessages: {
|
|
38
37
|
label: 'formFieldMessages',
|
|
39
38
|
padding: 0,
|
|
40
39
|
display: 'block',
|
|
41
|
-
margin: `calc(
|
|
40
|
+
margin: `calc(-${componentTheme.topMargin}) 0 0 0`,
|
|
41
|
+
...(props.gridArea && {
|
|
42
|
+
gridArea: props.gridArea
|
|
43
|
+
})
|
|
42
44
|
},
|
|
43
45
|
message: {
|
|
44
46
|
label: 'formFieldMessages__message',
|
package/es/FormPropTypes.js
CHANGED
|
@@ -25,6 +25,12 @@
|
|
|
25
25
|
import PropTypes from 'prop-types';
|
|
26
26
|
const formMessageTypePropType = PropTypes.oneOf(['error', 'newError', 'hint', 'success', 'screenreader-only']);
|
|
27
27
|
const formMessageChildPropType = PropTypes.node;
|
|
28
|
+
|
|
29
|
+
// TODO it will be easier if this would be just a string
|
|
30
|
+
/**
|
|
31
|
+
* The text to display in the form message
|
|
32
|
+
*/
|
|
33
|
+
|
|
28
34
|
/**
|
|
29
35
|
* ---
|
|
30
36
|
* category: utilities/form
|
package/es/index.js
CHANGED
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
export { FormField } from './FormField';
|
|
26
|
-
export { FormFieldLabel } from './FormFieldLabel';
|
|
27
26
|
export { FormFieldMessage } from './FormFieldMessage';
|
|
28
27
|
export { FormFieldMessages } from './FormFieldMessages';
|
|
29
28
|
export { FormFieldLayout } from './FormFieldLayout';
|
package/lib/FormField/index.js
CHANGED
package/lib/FormField/props.js
CHANGED
|
@@ -43,6 +43,7 @@ const propTypes = exports.propTypes = {
|
|
|
43
43
|
vAlign: _propTypes.default.oneOf(['top', 'middle', 'bottom']),
|
|
44
44
|
width: _propTypes.default.string,
|
|
45
45
|
inputContainerRef: _propTypes.default.func,
|
|
46
|
-
elementRef: _propTypes.default.func
|
|
46
|
+
elementRef: _propTypes.default.func,
|
|
47
|
+
margin: _propTypes.default.string
|
|
47
48
|
};
|
|
48
|
-
const allowedProps = exports.allowedProps = ['label', 'id', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'vAlign', 'width', 'inputContainerRef', 'elementRef'];
|
|
49
|
+
const allowedProps = exports.allowedProps = ['label', 'id', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'vAlign', 'width', 'inputContainerRef', 'elementRef', 'margin'];
|