@majoo-ui/react 2.4.9 → 2.4.10
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.
|
@@ -7,7 +7,7 @@ import 'core-js/modules/es.iterator.map.js';
|
|
|
7
7
|
import 'core-js/modules/es.iterator.reduce.js';
|
|
8
8
|
import { __rest, __awaiter } from 'tslib';
|
|
9
9
|
import * as React from 'react';
|
|
10
|
-
import { useState, useRef, useEffect, createElement } from 'react';
|
|
10
|
+
import { useState, useRef, useCallback, useEffect, createElement } from 'react';
|
|
11
11
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
12
12
|
import { renderToString } from 'react-dom/server';
|
|
13
13
|
import Downshift from 'downshift';
|
|
@@ -407,10 +407,20 @@ const InputSelect = /*#__PURE__*/React.forwardRef((_a, ref) => {
|
|
|
407
407
|
const [selectedValue, setSelectedValue] = useState(value);
|
|
408
408
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
409
409
|
const [query, setQuery] = useState();
|
|
410
|
-
const [openOptions, setOpenOptions] = useState(false);
|
|
411
410
|
const [open, setOpen] = useState(false);
|
|
412
411
|
const selectBoxRef = useRef(null);
|
|
413
412
|
const scrollerRef = useRef(null);
|
|
413
|
+
const downshiftMenuRef = useRef();
|
|
414
|
+
// The desktop menu shows only while Downshift's isOpen and the Popover's own open state are both true,
|
|
415
|
+
// and each one opens and closes itself: the search input toggles Downshift only while it is closed, the
|
|
416
|
+
// Popover trigger toggles on every click and also closes on outside press or ancestor scroll. Kept as two
|
|
417
|
+
// independent states they drifted out of phase, and from then on every click flipped both, so the menu
|
|
418
|
+
// never showed. Downshift is the source of truth; whatever the Popover decides is pushed into it.
|
|
419
|
+
const handlePopoverOpenChange = useCallback(popoverOpen => {
|
|
420
|
+
const downshiftMenu = downshiftMenuRef.current;
|
|
421
|
+
if (!downshiftMenu || downshiftMenu.isOpen === popoverOpen) return;
|
|
422
|
+
if (popoverOpen) downshiftMenu.openMenu();else downshiftMenu.closeMenu();
|
|
423
|
+
}, []);
|
|
414
424
|
useEffect(() => {
|
|
415
425
|
var _a;
|
|
416
426
|
if (search && Boolean(query)) {
|
|
@@ -428,7 +438,7 @@ const InputSelect = /*#__PURE__*/React.forwardRef((_a, ref) => {
|
|
|
428
438
|
}
|
|
429
439
|
};
|
|
430
440
|
scrollToSelectedElement();
|
|
431
|
-
}, [query, search,
|
|
441
|
+
}, [query, search, open, selectedIndex]);
|
|
432
442
|
const handleInputValue = (value, isReset = false) => {
|
|
433
443
|
if (onSearch && !isReset) onSearch(value);
|
|
434
444
|
if (fetchData) return;
|
|
@@ -536,9 +546,12 @@ const InputSelect = /*#__PURE__*/React.forwardRef((_a, ref) => {
|
|
|
536
546
|
}, [item]);
|
|
537
547
|
const stateReducer = (state, changes) => {
|
|
538
548
|
switch (changes.type) {
|
|
549
|
+
// A blurred toggle button must not close the menu (on mobile focus moves into the dialog the menu
|
|
550
|
+
// renders in), but it must not open a closed one either: the Popover follows isOpen, so that would
|
|
551
|
+
// pop the menu open whenever the user tabs away from the field.
|
|
539
552
|
case Downshift.stateChangeTypes.blurButton:
|
|
540
553
|
return {
|
|
541
|
-
isOpen:
|
|
554
|
+
isOpen: state.isOpen
|
|
542
555
|
};
|
|
543
556
|
// Downshift wipes selectedItem on Escape whenever its own isOpen is already false,
|
|
544
557
|
// firing onChange(null) on consumers that never asked to clear the selection.
|
|
@@ -581,17 +594,41 @@ const InputSelect = /*#__PURE__*/React.forwardRef((_a, ref) => {
|
|
|
581
594
|
getInputProps,
|
|
582
595
|
getItemProps,
|
|
583
596
|
isOpen,
|
|
597
|
+
openMenu,
|
|
598
|
+
closeMenu,
|
|
599
|
+
toggleMenu,
|
|
584
600
|
selectedItem,
|
|
585
601
|
highlightedIndex
|
|
586
602
|
}) => {
|
|
587
603
|
var _a, _b;
|
|
604
|
+
downshiftMenuRef.current = {
|
|
605
|
+
isOpen,
|
|
606
|
+
openMenu,
|
|
607
|
+
closeMenu
|
|
608
|
+
};
|
|
609
|
+
// Outside tests Downshift runs a toggle-button click in a setTimeout (an iOS blur workaround), while
|
|
610
|
+
// the Popover trigger toggles inside the click itself. The late toggle then undid the Popover sync,
|
|
611
|
+
// so on desktop the toggle happens in the same tick. The mobile dialog has no Popover and keeps
|
|
612
|
+
// Downshift's default.
|
|
613
|
+
const getDesktopToggleButtonProps = () => getToggleButtonProps({
|
|
614
|
+
disabled: disabled || readOnly,
|
|
615
|
+
onClick: event => {
|
|
616
|
+
event.preventDefault();
|
|
617
|
+
event.nativeEvent.preventDownshiftDefault = true;
|
|
618
|
+
toggleMenu();
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
const toggleButtonProps = isMobile ? getToggleButtonProps({
|
|
622
|
+
disabled: disabled || readOnly
|
|
623
|
+
}) : getDesktopToggleButtonProps();
|
|
588
624
|
const handleDownOption = () => {
|
|
589
625
|
if (hideArrowicon || noOptionIcon) {
|
|
590
626
|
return null;
|
|
591
627
|
}
|
|
592
|
-
return jsx(IconContainer, Object.assign({},
|
|
593
|
-
|
|
594
|
-
|
|
628
|
+
return jsx(IconContainer, Object.assign({}, toggleButtonProps, {
|
|
629
|
+
// Pressing the caret would blur the search input, and Downshift's deferred blur check closes the
|
|
630
|
+
// menu this click just opened whenever the button is already released by then.
|
|
631
|
+
onMouseDown: !isMobile ? event => event.preventDefault() : undefined,
|
|
595
632
|
disabled: disabled,
|
|
596
633
|
readOnly: readOnly,
|
|
597
634
|
children: jsx(CaretDownOutline, {
|
|
@@ -600,8 +637,8 @@ const InputSelect = /*#__PURE__*/React.forwardRef((_a, ref) => {
|
|
|
600
637
|
}));
|
|
601
638
|
};
|
|
602
639
|
return !isMobile ? jsx(Popover, {
|
|
603
|
-
open:
|
|
604
|
-
onOpenChange:
|
|
640
|
+
open: isOpen,
|
|
641
|
+
onOpenChange: handlePopoverOpenChange,
|
|
605
642
|
placement: placement,
|
|
606
643
|
hideOnScroll: true,
|
|
607
644
|
children: jsxs(SelectContainer, {
|
|
@@ -644,22 +681,17 @@ const InputSelect = /*#__PURE__*/React.forwardRef((_a, ref) => {
|
|
|
644
681
|
},
|
|
645
682
|
inputProps: getInputProps({
|
|
646
683
|
onChange: event => {
|
|
647
|
-
setOpenOptions(true);
|
|
648
684
|
if (event.type !== 'change') return;
|
|
649
685
|
const query = event.target.value;
|
|
650
686
|
if (!fetchData) handleInputValue(query);else debouncedSearch(query);
|
|
651
687
|
},
|
|
652
688
|
disabled
|
|
653
689
|
}),
|
|
654
|
-
onClick: !isOpen ?
|
|
655
|
-
disabled: disabled || readOnly
|
|
656
|
-
}).onClick : undefined
|
|
690
|
+
onClick: !isOpen ? toggleButtonProps.onClick : undefined
|
|
657
691
|
})
|
|
658
692
|
}) : jsx(Button, Object.assign({
|
|
659
693
|
ref: ref
|
|
660
|
-
},
|
|
661
|
-
disabled: disabled || readOnly
|
|
662
|
-
}), {
|
|
694
|
+
}, toggleButtonProps, {
|
|
663
695
|
disabled: disabled,
|
|
664
696
|
size: size,
|
|
665
697
|
readOnly: readOnly,
|
package/index.esm.css
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
.recharts-pie-sector {
|
|
2
|
-
outline: none;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
1
|
.rdw-option-wrapper {
|
|
6
2
|
padding: 5px;
|
|
7
3
|
min-width: 25px;
|
|
@@ -1049,6 +1045,10 @@
|
|
|
1049
1045
|
counter-reset: ol4;
|
|
1050
1046
|
}
|
|
1051
1047
|
|
|
1048
|
+
.recharts-pie-sector {
|
|
1049
|
+
outline: none;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
1052
|
.ReactCrop {
|
|
1053
1053
|
position: relative;
|
|
1054
1054
|
display: inline-block;
|