@db-ux/react-core-components 4.2.1 → 4.2.2
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,15 @@
|
|
|
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
|
+
|
|
3
13
|
## 4.2.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -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",
|
|
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",
|
|
46
|
+
"@db-ux/core-foundations": "4.2.2"
|
|
47
47
|
}
|
|
48
48
|
}
|