@db-ux/react-core-components 4.2.0 → 4.2.2-css-selectors-792dad7
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
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @db-ux/react-core-components
|
|
2
2
|
|
|
3
|
+
## 4.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix(form elements): `valid` background- and border-colors - [see commit 8f07e55](https://github.com/db-ux-design-system/core-web/commit/8f07e55f2155fcb619198857397ce354f90c4803)
|
|
8
|
+
|
|
9
|
+
- fix: set DBTabItem internal state `_selected` correctly - [see commit f7625cb](https://github.com/db-ux-design-system/core-web/commit/f7625cbd9d64513527e826c9d2c1ef42b2734a4b):
|
|
10
|
+
|
|
11
|
+
- Now also sets aria-selected=true|false correctly which improves screen reader behaviour
|
|
12
|
+
|
|
13
|
+
## 4.2.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- refactor(DBSwitch): Also toggle on pressing Enter key, not just Space - [see commit 95a7569](https://github.com/db-ux-design-system/core-web/commit/95a7569121ccf0fef318df4f23941c3f48a4a074)
|
|
18
|
+
|
|
3
19
|
## 4.2.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChangeEventProps, ChangeEventState, FocusEventProps, FocusEventState, FormCheckProps, FormMessageProps, FormProps, FormState, FromValidState, GlobalProps, GlobalState, IconLeadingProps, IconProps, IconTrailingProps, LabelVariantHorizontalType, SizeProps } from '../../shared/model';
|
|
1
|
+
import { ChangeEventProps, ChangeEventState, FocusEventProps, FocusEventState, FormCheckProps, FormMessageProps, FormProps, FormState, FromValidState, GeneralKeyboardEvent, GlobalProps, GlobalState, IconLeadingProps, IconProps, IconTrailingProps, LabelVariantHorizontalType, SizeProps } from '../../shared/model';
|
|
2
2
|
export type DBSwitchDefaultProps = {
|
|
3
3
|
/**
|
|
4
4
|
* Add additional icons to indicate active/inactive state.
|
|
@@ -10,5 +10,7 @@ export type DBSwitchDefaultProps = {
|
|
|
10
10
|
variant?: LabelVariantHorizontalType;
|
|
11
11
|
};
|
|
12
12
|
export type DBSwitchProps = GlobalProps & ChangeEventProps<HTMLInputElement> & FocusEventProps<HTMLInputElement> & FormProps & FormCheckProps & FormMessageProps & SizeProps & IconProps & IconTrailingProps & IconLeadingProps & DBSwitchDefaultProps;
|
|
13
|
-
export type DBSwitchDefaultState = {
|
|
13
|
+
export type DBSwitchDefaultState = {
|
|
14
|
+
handleKeyDown: (event: GeneralKeyboardEvent<HTMLInputElement>) => void;
|
|
15
|
+
};
|
|
14
16
|
export type DBSwitchState = DBSwitchDefaultState & GlobalState & ChangeEventState<HTMLInputElement> & FocusEventState<HTMLInputElement> & FormState & FromValidState;
|
|
@@ -68,6 +68,17 @@ function DBSwitchFn(props, component) {
|
|
|
68
68
|
props.onFocus(event);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
function handleKeyDown(event) {
|
|
72
|
+
var _a;
|
|
73
|
+
// Support ENTER key for toggling the switch (a11y requirement)
|
|
74
|
+
if (event.key === "Enter") {
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
// Toggle the switch by clicking it programmatically
|
|
77
|
+
if (!props.disabled) {
|
|
78
|
+
(_a = _ref.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
71
82
|
useEffect(() => {
|
|
72
83
|
var _a;
|
|
73
84
|
set_id((_a = props.id) !== null && _a !== void 0 ? _a : `switch-${uuid()}`);
|
|
@@ -110,7 +121,7 @@ function DBSwitchFn(props, component) {
|
|
|
110
121
|
}, []);
|
|
111
122
|
return (React.createElement("div", Object.assign({ "data-visual-aid": getBooleanAsString(props.visualAid), "data-size": props.size, "data-hide-label": getHideProp(props.showLabel), "data-variant": props.variant, "data-hide-asterisk": getHideProp(props.showRequiredAsterisk), "data-custom-validity": props.validation }, getRootProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font"]), { className: cls("db-switch", props.className) }),
|
|
112
123
|
React.createElement("label", { htmlFor: _id },
|
|
113
|
-
React.createElement("input", Object.assign({ type: "checkbox", role: "switch", id: _id, ref: _ref }, filterPassingProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font"]), { checked: getBoolean(props.checked, "checked"), value: props.value, disabled: getBoolean(props.disabled, "disabled"), "aria-invalid": props.validation === "invalid" ? "true" : undefined, "aria-describedby": _descByIds, name: props.name, required: getBoolean(props.required, "required"), "data-aid-icon": (_a = props.iconLeading) !== null && _a !== void 0 ? _a : props.icon, "data-aid-icon-trailing": props.iconTrailing, onChange: (event) => handleChange(event), onBlur: (event) => handleBlur(event), onFocus: (event) => handleFocus(event) })),
|
|
124
|
+
React.createElement("input", Object.assign({ type: "checkbox", role: "switch", id: _id, ref: _ref }, filterPassingProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font"]), { checked: getBoolean(props.checked, "checked"), value: props.value, disabled: getBoolean(props.disabled, "disabled"), "aria-invalid": props.validation === "invalid" ? "true" : undefined, "aria-describedby": _descByIds, name: props.name, required: getBoolean(props.required, "required"), "data-aid-icon": (_a = props.iconLeading) !== null && _a !== void 0 ? _a : props.icon, "data-aid-icon-trailing": props.iconTrailing, onChange: (event) => handleChange(event), onBlur: (event) => handleBlur(event), onFocus: (event) => handleFocus(event), onKeyDown: (event) => handleKeyDown(event) })),
|
|
114
125
|
props.label ? React.createElement(React.Fragment, null, props.label) : React.createElement(React.Fragment, null, props.children)),
|
|
115
126
|
stringPropVisible(props.message, props.showMessage) ? (React.createElement(DBInfotext, { size: "small", semantic: "adaptive", id: _messageId, icon: props.messageIcon }, props.message)) : null,
|
|
116
127
|
hasValidState() ? (React.createElement(DBInfotext, { size: "small", semantic: "successful", id: _validMessageId }, (_b = props.validMessage) !== null && _b !== void 0 ? _b : DEFAULT_VALID_MESSAGE)) : null,
|
|
@@ -20,5 +20,8 @@ export type DBTabItemDefaultProps = {
|
|
|
20
20
|
export type DBTabItemProps = GlobalProps & DBTabItemDefaultProps & IconProps & IconTrailingProps & IconLeadingProps & ShowIconLeadingProps & ShowIconTrailingProps & ActiveProps & ChangeEventProps<HTMLInputElement> & ShowIconProps & NameProps;
|
|
21
21
|
export type DBTabItemDefaultState = {
|
|
22
22
|
_selected: boolean;
|
|
23
|
+
_listenerAdded: boolean;
|
|
24
|
+
boundSetSelectedOnChange?: (event: any) => void;
|
|
25
|
+
setSelectedOnChange: (event: any) => void;
|
|
23
26
|
};
|
|
24
27
|
export type DBTabItemState = DBTabItemDefaultState & GlobalState & ChangeEventState<HTMLInputElement> & InitializedState & NameState;
|
|
@@ -9,6 +9,12 @@ function DBTabItemFn(props, component) {
|
|
|
9
9
|
const [_selected, set_selected] = useState(() => false);
|
|
10
10
|
const [_name, set_name] = useState(() => undefined);
|
|
11
11
|
const [initialized, setInitialized] = useState(() => false);
|
|
12
|
+
const [_listenerAdded, set_listenerAdded] = useState(() => false);
|
|
13
|
+
const [boundSetSelectedOnChange, setBoundSetSelectedOnChange] = useState(() => undefined);
|
|
14
|
+
function setSelectedOnChange(event) {
|
|
15
|
+
event.stopPropagation();
|
|
16
|
+
set_selected(event.target === _ref.current);
|
|
17
|
+
}
|
|
12
18
|
function handleNameAttribute() {
|
|
13
19
|
if (_ref.current) {
|
|
14
20
|
const setAttribute = _ref.current.setAttribute;
|
|
@@ -21,31 +27,47 @@ function DBTabItemFn(props, component) {
|
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
function handleChange(event) {
|
|
24
|
-
var _a;
|
|
25
|
-
event.stopPropagation();
|
|
26
30
|
if (props.onChange) {
|
|
27
31
|
props.onChange(event);
|
|
28
32
|
}
|
|
29
|
-
// We have different ts types in different frameworks, so we need to use any here
|
|
30
|
-
set_selected((_a = event.target) === null || _a === void 0 ? void 0 : _a["checked"]);
|
|
31
33
|
}
|
|
32
34
|
useEffect(() => {
|
|
35
|
+
setBoundSetSelectedOnChange(() => setSelectedOnChange);
|
|
33
36
|
setInitialized(true);
|
|
34
37
|
}, []);
|
|
35
38
|
useEffect(() => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
_ref.current.click();
|
|
39
|
-
}
|
|
39
|
+
var _a;
|
|
40
|
+
if (_ref.current && initialized && boundSetSelectedOnChange) {
|
|
40
41
|
handleNameAttribute();
|
|
41
42
|
setInitialized(false);
|
|
43
|
+
// deselect this tab when another tab in tablist is selected
|
|
44
|
+
if (!_listenerAdded) {
|
|
45
|
+
(_a = _ref.current
|
|
46
|
+
.closest("[role=tablist]")) === null || _a === void 0 ? void 0 : _a.addEventListener("change", boundSetSelectedOnChange);
|
|
47
|
+
set_listenerAdded(true);
|
|
48
|
+
}
|
|
49
|
+
// Initialize selected state from either active prop (set by parent) or checked attribute
|
|
50
|
+
if (props.active || _ref.current.checked) {
|
|
51
|
+
set_selected(true);
|
|
52
|
+
_ref.current.click();
|
|
53
|
+
}
|
|
42
54
|
}
|
|
43
|
-
}, [_ref.current, initialized]);
|
|
55
|
+
}, [_ref.current, initialized, boundSetSelectedOnChange]);
|
|
44
56
|
useEffect(() => {
|
|
45
57
|
if (props.name) {
|
|
46
58
|
set_name(props.name);
|
|
47
59
|
}
|
|
48
60
|
}, [props.name]);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
return () => {
|
|
63
|
+
var _a;
|
|
64
|
+
if (_listenerAdded && _ref.current && boundSetSelectedOnChange) {
|
|
65
|
+
(_a = _ref.current
|
|
66
|
+
.closest("[role=tablist]")) === null || _a === void 0 ? void 0 : _a.removeEventListener("change", boundSetSelectedOnChange);
|
|
67
|
+
set_listenerAdded(false);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}, []);
|
|
49
71
|
return (React.createElement("li", Object.assign({ role: "none" }, getRootProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font"]), { className: cls("db-tab-item", props.className) }),
|
|
50
72
|
React.createElement("label", { htmlFor: props.id, "data-icon": (_a = props.iconLeading) !== null && _a !== void 0 ? _a : props.icon, "data-icon-trailing": props.iconTrailing, "data-show-icon": getBooleanAsString((_b = props.showIconLeading) !== null && _b !== void 0 ? _b : props.showIcon), "data-show-icon-trailing": getBooleanAsString(props.showIconTrailing), "data-no-text": getBooleanAsString(props.noText) },
|
|
51
73
|
React.createElement("input", Object.assign({ type: "radio", role: "tab", disabled: getBoolean(props.disabled, "disabled"), "aria-selected": _selected, checked: getBoolean(props.checked, "checked"), ref: _ref }, filterPassingProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font"]), { name: _name, id: props.id, onInput: (event) => handleChange(event) })),
|
|
@@ -123,9 +123,9 @@ function DBTabsFn(props, component) {
|
|
|
123
123
|
if (tabItem) {
|
|
124
124
|
const list = tabItem.parentElement;
|
|
125
125
|
if (list) {
|
|
126
|
-
const
|
|
126
|
+
const tabIndex = Array.from(list.children).indexOf(tabItem);
|
|
127
127
|
if (props.onIndexChange) {
|
|
128
|
-
props.onIndexChange(
|
|
128
|
+
props.onIndexChange(tabIndex);
|
|
129
129
|
}
|
|
130
130
|
if (props.onTabSelect) {
|
|
131
131
|
props.onTabSelect(event);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@db-ux/react-core-components",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.2-css-selectors-792dad7",
|
|
4
4
|
"description": "React components for @db-ux/core-components",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"sideEffects": false,
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@db-ux/core-components": "4.2.
|
|
46
|
-
"@db-ux/core-foundations": "4.2.
|
|
45
|
+
"@db-ux/core-components": "4.2.2-css-selectors-792dad7",
|
|
46
|
+
"@db-ux/core-foundations": "4.2.2-css-selectors-792dad7"
|
|
47
47
|
}
|
|
48
48
|
}
|