@vitality-ds/components 4.9.2 → 4.9.4
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/dist/Form/FormField/components/FormFieldLabel/index.spec.js +4 -0
- package/dist/Form/FormField/index.js +3 -1
- package/dist/Form/FormField/logic.js +4 -1
- package/dist/Form/Label/index.js +4 -2
- package/dist/components/src/DropdownMenu/types.d.ts +1 -1
- package/dist/components/src/Form/FormField/components/FormFieldLabel/types.d.ts +4 -0
- package/dist/components/src/Form/FormField/logic.d.ts +1 -0
- package/dist/components/src/Form/Label/index.d.ts +1 -1
- package/dist/esm/Form/FormField/components/FormFieldLabel/index.spec.js +4 -0
- package/dist/esm/Form/FormField/index.js +4 -2
- package/dist/esm/Form/FormField/logic.js +3 -0
- package/dist/esm/Form/Label/index.js +4 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
var _react = require("@testing-library/react");
|
|
5
5
|
var _react2 = _interopRequireDefault(require("react"));
|
|
6
|
+
var _logic = require("../../logic");
|
|
6
7
|
var _index = _interopRequireDefault(require("./index"));
|
|
7
8
|
describe("getInputComponent", function () {
|
|
8
9
|
it("should return a <label> component when no fieldType is provided", function () {
|
|
9
10
|
var _render = (0, _react.render)(/*#__PURE__*/_react2["default"].createElement(_index["default"], {
|
|
11
|
+
id: (0, _logic.getLabelledById)("foo"),
|
|
10
12
|
fieldType: "text",
|
|
11
13
|
content: "Foo",
|
|
12
14
|
htmlFor: "foo"
|
|
@@ -16,6 +18,7 @@ describe("getInputComponent", function () {
|
|
|
16
18
|
});
|
|
17
19
|
it("should return a <label> component when no fieldType `text` is provided", function () {
|
|
18
20
|
var _render2 = (0, _react.render)(/*#__PURE__*/_react2["default"].createElement(_index["default"], {
|
|
21
|
+
id: (0, _logic.getLabelledById)("foo"),
|
|
19
22
|
fieldType: "text",
|
|
20
23
|
content: "Foo",
|
|
21
24
|
htmlFor: "foo"
|
|
@@ -25,6 +28,7 @@ describe("getInputComponent", function () {
|
|
|
25
28
|
});
|
|
26
29
|
it("should return a <legend> element when passed a checkbox type", function () {
|
|
27
30
|
var _render3 = (0, _react.render)(/*#__PURE__*/_react2["default"].createElement(_index["default"], {
|
|
31
|
+
id: (0, _logic.getLabelledById)("foo"),
|
|
28
32
|
fieldType: "checkbox",
|
|
29
33
|
content: "Foo",
|
|
30
34
|
htmlFor: "foo"
|
|
@@ -35,6 +35,7 @@ function FormField(_ref) {
|
|
|
35
35
|
var Component = inputComponent.component;
|
|
36
36
|
var ariaDescribedById = (0, _logic.getDescribedById)(id);
|
|
37
37
|
var ariaErrorId = (0, _logic.getErrorMessageId)(id);
|
|
38
|
+
var ariaLabelledById = (0, _logic.getLabelledById)(id);
|
|
38
39
|
return /*#__PURE__*/_react["default"].createElement(_Fieldset["default"], restProps, /*#__PURE__*/_react["default"].createElement(_Stack["default"], {
|
|
39
40
|
spacing: "sm",
|
|
40
41
|
direction: "horizontal",
|
|
@@ -45,6 +46,7 @@ function FormField(_ref) {
|
|
|
45
46
|
fieldType: type,
|
|
46
47
|
content: label,
|
|
47
48
|
htmlFor: id,
|
|
49
|
+
id: ariaLabelledById,
|
|
48
50
|
required: required,
|
|
49
51
|
hasError: hasError
|
|
50
52
|
})), infoTooltipContent && /*#__PURE__*/_react["default"].createElement(_Box["default"], {
|
|
@@ -61,7 +63,7 @@ function FormField(_ref) {
|
|
|
61
63
|
onChange: onChange,
|
|
62
64
|
value: value,
|
|
63
65
|
id: id,
|
|
64
|
-
"aria-labelledby":
|
|
66
|
+
"aria-labelledby": ariaLabelledById,
|
|
65
67
|
"aria-describedby": ariaDescribedById,
|
|
66
68
|
"aria-required": required,
|
|
67
69
|
"aria-errormessage": ariaErrorId,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getInputComponent = exports.getErrorMessageId = exports.getDescribedById = void 0;
|
|
6
|
+
exports.getLabelledById = exports.getInputComponent = exports.getErrorMessageId = exports.getDescribedById = void 0;
|
|
7
7
|
var _constants = require("./constants");
|
|
8
8
|
// eslint-disable-next-line import/prefer-default-export
|
|
9
9
|
var getInputComponent = exports.getInputComponent = function getInputComponent(type) {
|
|
@@ -14,4 +14,7 @@ var getDescribedById = exports.getDescribedById = function getDescribedById(id)
|
|
|
14
14
|
};
|
|
15
15
|
var getErrorMessageId = exports.getErrorMessageId = function getErrorMessageId(id) {
|
|
16
16
|
return "vitality-errorMessage-".concat(id);
|
|
17
|
+
};
|
|
18
|
+
var getLabelledById = exports.getLabelledById = function getLabelledById(id) {
|
|
19
|
+
return "vitality-labelledBy-".concat(id);
|
|
17
20
|
};
|
package/dist/Form/Label/index.js
CHANGED
|
@@ -11,9 +11,11 @@ function Label(_ref) {
|
|
|
11
11
|
var content = _ref.content,
|
|
12
12
|
htmlFor = _ref.htmlFor,
|
|
13
13
|
required = _ref.required,
|
|
14
|
-
hasError = _ref.hasError
|
|
14
|
+
hasError = _ref.hasError,
|
|
15
|
+
id = _ref.id;
|
|
15
16
|
return /*#__PURE__*/_react["default"].createElement(_styled.BaseLabel, {
|
|
16
|
-
htmlFor: htmlFor
|
|
17
|
+
htmlFor: htmlFor,
|
|
18
|
+
id: id
|
|
17
19
|
}, content, required && /*#__PURE__*/_react["default"].createElement(_styled.BaseLabelRequired, {
|
|
18
20
|
hasError: hasError
|
|
19
21
|
}, "*"));
|
|
@@ -27,7 +27,7 @@ export declare type TriggerComponentTypes = {
|
|
|
27
27
|
iconButton: Omit<IconButtonProps, "onClick" | "disabled"> & NeverOnClick & NeverDisableTriggerThroughTriggerProps;
|
|
28
28
|
avatar: Omit<AvatarButtonType, "onClick" | "disabled"> & NeverOnClick & NeverDisableTriggerThroughTriggerProps;
|
|
29
29
|
button: Omit<ButtonProps, "onClick" | "disabled"> & NeverOnClick & NeverDisableTriggerThroughTriggerProps & {
|
|
30
|
-
"data-vitality-component"
|
|
30
|
+
"data-vitality-component"?: string;
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
33
|
export declare type TriggerComponents = typeof Button | typeof IconButton | typeof AvatarButton;
|
|
@@ -16,6 +16,10 @@ export declare type FormFieldLabelProps<T> = ExcludedProps & {
|
|
|
16
16
|
* Indicate whether or not the associated input field is required
|
|
17
17
|
*/
|
|
18
18
|
required?: valueof<Pick<CommonProps, "required">>;
|
|
19
|
+
/**
|
|
20
|
+
* The id of the label element
|
|
21
|
+
*/
|
|
22
|
+
id: valueof<Pick<HTMLLabelElement, "id">>;
|
|
19
23
|
/**
|
|
20
24
|
* Id used for the htmlFor attribute that should match the input's id
|
|
21
25
|
*/
|
|
@@ -2,3 +2,4 @@ import type { InputComponent, InputTypes } from "./types";
|
|
|
2
2
|
export declare const getInputComponent: (type: InputTypes) => InputComponent<InputTypes>;
|
|
3
3
|
export declare const getDescribedById: (id: string) => string;
|
|
4
4
|
export declare const getErrorMessageId: (id: string) => string;
|
|
5
|
+
export declare const getLabelledById: (id: string) => string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { LabelProps } from "./types";
|
|
3
|
-
declare function Label({ content, htmlFor, required, hasError }: LabelProps): JSX.Element;
|
|
3
|
+
declare function Label({ content, htmlFor, required, hasError, id }: LabelProps): JSX.Element;
|
|
4
4
|
export default Label;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { render } from "@testing-library/react";
|
|
2
2
|
import React from "react";
|
|
3
|
+
import { getLabelledById } from "../../logic";
|
|
3
4
|
import FormFieldLabel from "./index";
|
|
4
5
|
describe("getInputComponent", function () {
|
|
5
6
|
it("should return a <label> component when no fieldType is provided", function () {
|
|
6
7
|
var _render = render(/*#__PURE__*/React.createElement(FormFieldLabel, {
|
|
8
|
+
id: getLabelledById("foo"),
|
|
7
9
|
fieldType: "text",
|
|
8
10
|
content: "Foo",
|
|
9
11
|
htmlFor: "foo"
|
|
@@ -13,6 +15,7 @@ describe("getInputComponent", function () {
|
|
|
13
15
|
});
|
|
14
16
|
it("should return a <label> component when no fieldType `text` is provided", function () {
|
|
15
17
|
var _render2 = render(/*#__PURE__*/React.createElement(FormFieldLabel, {
|
|
18
|
+
id: getLabelledById("foo"),
|
|
16
19
|
fieldType: "text",
|
|
17
20
|
content: "Foo",
|
|
18
21
|
htmlFor: "foo"
|
|
@@ -22,6 +25,7 @@ describe("getInputComponent", function () {
|
|
|
22
25
|
});
|
|
23
26
|
it("should return a <legend> element when passed a checkbox type", function () {
|
|
24
27
|
var _render3 = render(/*#__PURE__*/React.createElement(FormFieldLabel, {
|
|
28
|
+
id: getLabelledById("foo"),
|
|
25
29
|
fieldType: "checkbox",
|
|
26
30
|
content: "Foo",
|
|
27
31
|
htmlFor: "foo"
|
|
@@ -10,7 +10,7 @@ import Tooltip from "../../Tooltip";
|
|
|
10
10
|
import HelperMessage from "../HelperMessage";
|
|
11
11
|
import Fieldset from "./components/Fieldset";
|
|
12
12
|
import FormFieldLabel from "./components/FormFieldLabel";
|
|
13
|
-
import { getDescribedById, getErrorMessageId, getInputComponent } from "./logic";
|
|
13
|
+
import { getDescribedById, getErrorMessageId, getInputComponent, getLabelledById } from "./logic";
|
|
14
14
|
import { IconWrapper } from "./styled";
|
|
15
15
|
function FormField(_ref) {
|
|
16
16
|
var label = _ref.label,
|
|
@@ -28,6 +28,7 @@ function FormField(_ref) {
|
|
|
28
28
|
var Component = inputComponent.component;
|
|
29
29
|
var ariaDescribedById = getDescribedById(id);
|
|
30
30
|
var ariaErrorId = getErrorMessageId(id);
|
|
31
|
+
var ariaLabelledById = getLabelledById(id);
|
|
31
32
|
return /*#__PURE__*/React.createElement(Fieldset, restProps, /*#__PURE__*/React.createElement(Stack, {
|
|
32
33
|
spacing: "sm",
|
|
33
34
|
direction: "horizontal",
|
|
@@ -38,6 +39,7 @@ function FormField(_ref) {
|
|
|
38
39
|
fieldType: type,
|
|
39
40
|
content: label,
|
|
40
41
|
htmlFor: id,
|
|
42
|
+
id: ariaLabelledById,
|
|
41
43
|
required: required,
|
|
42
44
|
hasError: hasError
|
|
43
45
|
})), infoTooltipContent && /*#__PURE__*/React.createElement(Box, {
|
|
@@ -54,7 +56,7 @@ function FormField(_ref) {
|
|
|
54
56
|
onChange: onChange,
|
|
55
57
|
value: value,
|
|
56
58
|
id: id,
|
|
57
|
-
"aria-labelledby":
|
|
59
|
+
"aria-labelledby": ariaLabelledById,
|
|
58
60
|
"aria-describedby": ariaDescribedById,
|
|
59
61
|
"aria-required": required,
|
|
60
62
|
"aria-errormessage": ariaErrorId,
|
|
@@ -8,4 +8,7 @@ export var getDescribedById = function getDescribedById(id) {
|
|
|
8
8
|
};
|
|
9
9
|
export var getErrorMessageId = function getErrorMessageId(id) {
|
|
10
10
|
return "vitality-errorMessage-".concat(id);
|
|
11
|
+
};
|
|
12
|
+
export var getLabelledById = function getLabelledById(id) {
|
|
13
|
+
return "vitality-labelledBy-".concat(id);
|
|
11
14
|
};
|
|
@@ -4,9 +4,11 @@ function Label(_ref) {
|
|
|
4
4
|
var content = _ref.content,
|
|
5
5
|
htmlFor = _ref.htmlFor,
|
|
6
6
|
required = _ref.required,
|
|
7
|
-
hasError = _ref.hasError
|
|
7
|
+
hasError = _ref.hasError,
|
|
8
|
+
id = _ref.id;
|
|
8
9
|
return /*#__PURE__*/React.createElement(BaseLabel, {
|
|
9
|
-
htmlFor: htmlFor
|
|
10
|
+
htmlFor: htmlFor,
|
|
11
|
+
id: id
|
|
10
12
|
}, content, required && /*#__PURE__*/React.createElement(BaseLabelRequired, {
|
|
11
13
|
hasError: hasError
|
|
12
14
|
}, "*"));
|