Skip to content

Commit 68e22c8

Browse files
author
Krzysztof Wilk
committed
Generate version 2.4.0
1 parent 07e4a6c commit 68e22c8

File tree

6 files changed

+37
-9
lines changed

6 files changed

+37
-9
lines changed

README.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MDB 5 React
22

3-
Version: FREE 2.3.0
3+
Version: FREE 2.4.0
44

55
Documentation:
66
https://mdbootstrap.com/docs/b5/react/

app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mdb-react-ui-kit-demo",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"main": "index.js",
55
"repository": {
66
"type": "git",

app/src/components/Modal/Modal.tsx

+31-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const MDBModal: React.FC<ModalProps> = ({
2323
const [innerShow, setInnerShow] = useState(show);
2424
const [staticModal, setStaticModal] = useState(false);
2525
const [focusedElement, setFocusedElement] = useState(0);
26+
const [focusableElements, setFocusableElements] = useState<any>([]);
2627

2728
const modalInnerRef = useRef<HTMLElement>(null);
2829
const modalReference = modalRef ? modalRef : modalInnerRef;
@@ -90,10 +91,30 @@ const MDBModal: React.FC<ModalProps> = ({
9091
);
9192

9293
useEffect(() => {
93-
const focusableElements = modalReference.current?.querySelectorAll(
94-
'button, a, input, select, textarea, [tabindex]:not([tabindex="-1"])'
95-
);
94+
const focusable = modalReference.current?.querySelectorAll(
95+
'button, a, input, select, textarea, [tabindex]'
96+
) as any as Array<HTMLElement>;
97+
98+
const filtered = Array.from(focusable)
99+
.filter((el: any) => el.tabIndex !== -1)
100+
.sort((a, b) => {
101+
if (a.tabIndex === b.tabIndex) {
102+
return 0;
103+
}
104+
if (b.tabIndex === null) {
105+
return -1;
106+
}
107+
if (a.tabIndex === null) {
108+
return 1;
109+
}
110+
return a.tabIndex - b.tabIndex;
111+
});
96112

113+
setFocusableElements(filtered);
114+
setFocusedElement(filtered.length - 1);
115+
}, [modalReference]);
116+
117+
useEffect(() => {
97118
if (focusableElements && focusableElements.length > 0) {
98119
if (focusedElement === focusableElements.length) {
99120
(focusableElements[0] as HTMLElement).focus();
@@ -102,7 +123,7 @@ const MDBModal: React.FC<ModalProps> = ({
102123
(focusableElements[focusedElement] as HTMLElement).focus();
103124
}
104125
}
105-
}, [focusedElement, modalReference]);
126+
}, [focusedElement, focusableElements]);
106127

107128
useEffect(() => {
108129
const getScrollbarWidth = () => {
@@ -122,6 +143,12 @@ const MDBModal: React.FC<ModalProps> = ({
122143
document.body.style.overflow = '';
123144
document.body.style.paddingRight = '';
124145
}
146+
147+
return () => {
148+
document.body.classList.remove('modal-open');
149+
document.body.style.overflow = '';
150+
document.body.style.paddingRight = '';
151+
};
125152
}, [innerShow]);
126153

127154
useEffect(() => {

dist/mdb-react-ui-kit.esm.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mdb-react-ui-kit.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mdb-react-ui-kit",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"main": "./dist/mdb-react-ui-kit.js",
55
"module": "./dist/mdb-react-ui-kit.esm.js",
66
"types": "./dist/index.d.ts",
@@ -36,6 +36,7 @@
3636
],
3737
"author": "MDBootstrap",
3838
"license": "SEE LICENSE IN <license.pdf>",
39+
"homepage": "https://mdbootstrap.com/docs/b5/react/",
3940
"bugs": {
4041
"url": "https://github.com/mdbootstrap/mdb-react-ui-kit/issues"
4142
}

0 commit comments

Comments
 (0)