Skip to content

Commit da743a6

Browse files
committed
release: 6.1.0
1 parent 4dc0332 commit da743a6

File tree

184 files changed

+6405
-4537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+6405
-4537
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 6.0.0
3+
Version: FREE 6.1.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": "6.0.0",
3+
"version": "6.1.0",
44
"main": "index.js",
55
"repository": {
66
"type": "git",

app/src/components/Collapse/Collapse.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import type { CollapseProps } from './types';
55
const MDBCollapse: React.FC<CollapseProps> = ({
66
className,
77
children,
8-
show,
8+
show = false,
99
id,
1010
navbar,
1111
tag: Tag,
1212
collapseRef,
1313
style,
14+
onShow,
15+
onHide,
1416
...props
1517
}): JSX.Element => {
1618
const [showCollapse, setShowCollapse] = useState<boolean | undefined>(false);
@@ -39,7 +41,10 @@ const MDBCollapse: React.FC<CollapseProps> = ({
3941
}, [collapseHeight, showCollapse, refCollapse]);
4042

4143
useEffect(() => {
42-
setShowCollapse(show);
44+
if (showCollapse !== show) {
45+
show ? onShow?.() : onHide?.();
46+
setShowCollapse(show);
47+
}
4348

4449
if (showCollapse) {
4550
setTransition(true);
@@ -52,7 +57,7 @@ const MDBCollapse: React.FC<CollapseProps> = ({
5257
return () => {
5358
clearTimeout(timer);
5459
};
55-
}, [show, showCollapse]);
60+
}, [show, showCollapse, onShow, onHide]);
5661

5762
useEffect(() => {
5863
if (showCollapse) {

app/src/components/Dropdown/DropdownItem/DropdownItem.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ const MDBDropdownItem = ({
1818
preventCloseOnClick,
1919
...props
2020
}: DropdownItemProps) => {
21-
const { setIsOpenState, onHide } = useDropdownContext();
21+
const { setIsOpenState, onHide, setActiveIndex } = useDropdownContext();
2222

2323
const handleClose = (e: MouseEvent<HTMLElement>) => {
24-
if (disabled || preventCloseOnClick) return;
24+
onHide?.(e);
25+
onClick?.(e);
26+
if (disabled || preventCloseOnClick || e.defaultPrevented) {
27+
return;
28+
}
2529

26-
onHide?.();
30+
setTimeout(() => setActiveIndex(-1), 300);
2731
setIsOpenState(false);
28-
onClick?.(e);
2932
};
3033

3134
return (

app/src/components/Dropdown/DropdownMenu/DropdownMenu.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const MDBDropdownMenu = ({
4646
return 'left-start';
4747
}
4848

49-
const isEnd = popperElement && getComputedStyle(popperElement).getPropertyValue('--bs-position').trim() === 'end';
49+
const isEnd = popperElement && getComputedStyle(popperElement).getPropertyValue('--mdb-position').trim() === 'end';
5050

5151
if (dropup) {
5252
return isEnd ? 'top-end' : 'top-start';

app/src/components/Dropdown/DropdownToggle/DropdownToggle.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ const MDBDropdownToggle = ({
1717
const classes = clsx('dropdown-toggle', split && 'dropdown-toggle-split', className);
1818

1919
const handleOpenToggle = (e: MouseEvent<HTMLElement>) => {
20-
isOpenState ? onHide?.() : onShow?.();
20+
onClick?.(e);
21+
isOpenState ? onHide?.(e) : onShow?.(e);
2122

23+
if (e.defaultPrevented) {
24+
return;
25+
}
2226
setIsOpenState((prev) => !prev);
23-
onClick?.(e);
2427

2528
setTimeout(() => setActiveIndex(-1), 300);
2629
};

app/src/components/Dropdown/contexts/types.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dispatch, SetStateAction, ReactNode } from 'react';
1+
import { Dispatch, SetStateAction, ReactNode, SyntheticEvent } from 'react';
22

33
export interface Dropdown {
44
activeIndex: number;
@@ -10,8 +10,8 @@ export interface Dropdown {
1010
setActiveIndex: Dispatch<SetStateAction<number>>;
1111
setPopperElement: Dispatch<SetStateAction<HTMLElement | null>>;
1212
setReferenceElement: Dispatch<SetStateAction<HTMLElement | null>>;
13-
onHide?: () => any;
14-
onShow?: () => any;
13+
onHide?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
14+
onShow?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
1515
dropup?: boolean;
1616
dropright?: boolean;
1717
dropleft?: boolean;
@@ -26,6 +26,6 @@ export interface DropdownProviderProps {
2626
dropup?: boolean;
2727
dropright?: boolean;
2828
dropleft?: boolean;
29-
onHide?: () => any;
30-
onShow?: () => any;
29+
onHide?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
30+
onShow?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
3131
}

app/src/components/Dropdown/hooks/useClickOutside.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
import { useCallback, useEffect } from 'react';
1+
import { ReactPropTypes, SyntheticEvent, useCallback, useEffect } from 'react';
22
import { isNode } from '../helpers/typeguards';
33
import { useDropdownContext } from './useDropdownContext';
44

55
export const useClickOutside = () => {
66
const { isOpenState, setIsOpenState, setActiveIndex, popperElement, referenceElement, onHide } = useDropdownContext();
77

88
const handleClickOutside = useCallback(
9-
({ target }: MouseEvent) => {
9+
(e: MouseEvent | SyntheticEvent) => {
10+
onHide?.(e);
1011
if (
1112
!isOpenState ||
12-
!isNode(target) ||
13-
(popperElement && popperElement.contains(target)) ||
14-
(referenceElement && referenceElement.contains(target))
15-
)
13+
!isNode(e.target) ||
14+
(popperElement && popperElement.contains(e.target)) ||
15+
(referenceElement && referenceElement.contains(e.target)) ||
16+
e.defaultPrevented
17+
) {
1618
return;
17-
19+
}
1820
setIsOpenState(false);
19-
onHide?.();
21+
2022
setTimeout(() => setActiveIndex(-1), 300);
2123
},
2224
[isOpenState, setIsOpenState, setActiveIndex, popperElement, referenceElement, onHide]

app/src/components/Dropdown/hooks/useKeyboard.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,27 @@ export const useKeyboard = (children: ReactElement[] | ReactElement) => {
5050
if (e.key === 'Enter') {
5151
const el: HTMLElement | null = document.querySelector('[data-active="true"]');
5252
const child = el?.firstElementChild as HTMLElement | null | undefined;
53-
child?.click();
5453

54+
if (child) {
55+
return child.click();
56+
}
57+
58+
onHide?.(e);
59+
60+
if (e.defaultPrevented) {
61+
return;
62+
}
5563
setIsOpenState(false);
5664
setTimeout(() => setActiveIndex(-1), 300);
5765
}
5866

5967
if (e.key === 'Escape') {
60-
setIsOpenState(false);
61-
onHide?.();
68+
onHide?.(e);
69+
if (e.defaultPrevented) {
70+
return;
71+
}
6272

73+
setIsOpenState(false);
6374
setTimeout(() => setActiveIndex(-1), 300);
6475
}
6576
},

app/src/components/Dropdown/types.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseComponent } from '../../types/baseComponent';
2-
import { ReactNode, ComponentProps } from 'react';
2+
import { ReactNode, ComponentProps, SyntheticEvent } from 'react';
33

44
export interface DropdownProps extends BaseComponent {
55
animation?: boolean;
@@ -11,6 +11,6 @@ export interface DropdownProps extends BaseComponent {
1111
dropleft?: boolean;
1212
children?: ReactNode;
1313
tag?: ComponentProps<any>;
14-
onHide?: () => any;
15-
onShow?: () => any;
14+
onHide?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
15+
onShow?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
1616
}

app/src/components/Modal/Modal.tsx

+19-11
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const MDBModal: React.FC<ModalProps> = ({
3131

3232
const modalInnerRef = useRef<HTMLElement>(null);
3333
const modalReference = modalRef ? modalRef : modalInnerRef;
34-
3534
const classes = clsx(
3635
'modal',
3736
staticModal && 'modal-static',
@@ -44,8 +43,10 @@ const MDBModal: React.FC<ModalProps> = ({
4443
const backdropClasses = clsx('modal-backdrop', 'fade', isOpenBackdrop && 'show');
4544

4645
const closeModal = useCallback(() => {
47-
setIsOpenModal(false);
48-
isOpenModal && onHide?.();
46+
setIsOpenModal((isCurrentlyShown) => {
47+
isCurrentlyShown && onHide?.();
48+
return false;
49+
});
4950

5051
setTimeout(() => {
5152
setIsOpenBackrop(false);
@@ -59,6 +60,10 @@ const MDBModal: React.FC<ModalProps> = ({
5960

6061
const handleClickOutside = useCallback(
6162
(event: MouseEvent) => {
63+
if (nonInvasive) {
64+
return;
65+
}
66+
6267
if (isOpenModal && event.target === modalReference.current) {
6368
if (!staticBackdrop) {
6469
closeModal();
@@ -71,7 +76,7 @@ const MDBModal: React.FC<ModalProps> = ({
7176
}
7277
}
7378
},
74-
[isOpenModal, modalReference, staticBackdrop, closeModal, onHidePrevented]
79+
[isOpenModal, modalReference, staticBackdrop, closeModal, onHidePrevented, nonInvasive]
7580
);
7681

7782
const handleKeydown = useCallback(
@@ -177,16 +182,19 @@ const MDBModal: React.FC<ModalProps> = ({
177182
}, [show, closeModal, setShow, onShow]);
178183

179184
useEffect(() => {
180-
if (!nonInvasive) {
181-
window.addEventListener('click', handleClickOutside);
182-
window.addEventListener('keydown', handleKeydown);
183-
}
185+
const addMouseUpListener = (e: MouseEvent) => {
186+
if (!(e.target as HTMLElement).closest('.modal-dialog')) {
187+
window.addEventListener('mouseup', handleClickOutside, { once: true });
188+
}
189+
};
190+
window.addEventListener('mousedown', addMouseUpListener);
191+
window.addEventListener('keydown', handleKeydown);
184192

185193
return () => {
186-
window.removeEventListener('click', handleClickOutside);
194+
window.removeEventListener('mousedown', addMouseUpListener);
187195
window.removeEventListener('keydown', handleKeydown);
188196
};
189-
}, [handleKeydown, handleClickOutside, nonInvasive]);
197+
}, [handleKeydown, handleClickOutside]);
190198

191199
const appendToBodyTemplate = (
192200
<>
@@ -224,7 +232,7 @@ const MDBModal: React.FC<ModalProps> = ({
224232
{children}
225233
</Tag>
226234
{ReactDOM.createPortal(
227-
backdrop && innerShow && !nonInvasive && <div className={backdropClasses}></div>,
235+
backdrop && innerShow && !nonInvasive && <div onClick={closeModal} className={backdropClasses}></div>,
228236
document.body
229237
)}
230238
</>

app/src/components/Tooltip/Tooltip.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, useCallback } from 'react';
1+
import React, { useState, useEffect, useCallback, SyntheticEvent } from 'react';
22
import ReactDOM from 'react-dom';
33
import clsx from 'clsx';
44
import { usePopper } from 'react-popper';
@@ -58,16 +58,16 @@ const MDBTooltip: React.FC<TooltipProps> = ({
5858
};
5959
}, [isOpenState, isClicked]);
6060

61-
const handleOnMouseEnter = (e: any) => {
62-
setIsOpenState(true);
63-
onShow?.();
64-
onMouseEnter && onMouseEnter(e);
61+
const handleOnMouseEnter = (e: SyntheticEvent) => {
62+
onShow?.(e);
63+
!e.defaultPrevented && setIsOpenState(true);
64+
onMouseEnter?.(e);
6565
};
6666

67-
const handleOnMouseLeave = (e: any) => {
68-
setIsOpenState(false);
69-
onHide?.();
70-
onMouseLeave && onMouseLeave(e);
67+
const handleOnMouseLeave = (e: SyntheticEvent) => {
68+
onHide?.(e);
69+
!e.defaultPrevented && setIsOpenState(false);
70+
onMouseLeave?.(e);
7171
};
7272

7373
const handleClick = useCallback(

app/src/components/Tooltip/types.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MouseEventHandler, SyntheticEvent } from 'react';
12
import { BaseComponent } from '../../types/baseComponent';
23
import { placement } from '../../types/placement';
34

@@ -10,8 +11,10 @@ interface TooltipProps extends BaseComponent {
1011
title?: React.ReactNode;
1112
wrapperProps?: Record<string, unknown>;
1213
wrapperClass?: string;
13-
onShow?: () => any;
14-
onHide?: () => any;
14+
onShow?: (e: SyntheticEvent) => any;
15+
onHide?: (e: SyntheticEvent) => any;
16+
onMouseEnter?: (e: SyntheticEvent) => any;
17+
onMouseLeave?: (e: SyntheticEvent) => any;
1518
}
1619

1720
export { TooltipProps };

app/src/forms/Input/Input.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ const MDBInput: React.FC<InputProps> = React.forwardRef<HTMLInputElement, InputP
5454

5555
const { value } = innerRef.current;
5656

57-
value.length > 0 ? setActive(true) : setActive(false);
57+
value != '' ? setActive(true) : setActive(false);
5858
}, [innerRef.current?.value]);
5959

6060
useEffect(() => {
6161
if (value === undefined) return;
62-
value.toString().length > 0 ? setActive(true) : setActive(false);
62+
value != '' ? setActive(true) : setActive(false);
6363
}, [value]);
6464

6565
useEffect(() => {
6666
if (defaultValue === undefined) return;
67-
defaultValue.toString().length > 0 ? setActive(true) : setActive(false);
67+
defaultValue != '' ? setActive(true) : setActive(false);
6868
}, [defaultValue]);
6969

7070
const setWidth = useCallback(() => {
@@ -87,9 +87,9 @@ const MDBInput: React.FC<InputProps> = React.forwardRef<HTMLInputElement, InputP
8787
if (!innerRef.current) return;
8888

8989
if (
90-
(newValue !== undefined && newValue.toString().length > 0) ||
91-
(value !== undefined && value.toString().length > 0) ||
92-
innerRef.current.value.length > 0
90+
(newValue !== undefined && newValue != '') ||
91+
(value !== undefined && value != '') ||
92+
innerRef.current.value != ''
9393
) {
9494
setActive(true);
9595
} else {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)