@patternfly/react-core 4.192.8 → 4.192.12
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 +41 -0
- package/dist/esm/components/Select/Select.d.ts +5 -1
- package/dist/esm/components/Select/Select.d.ts.map +1 -1
- package/dist/esm/components/Select/Select.js +171 -28
- package/dist/esm/components/Select/Select.js.map +1 -1
- package/dist/esm/components/Select/SelectMenu.d.ts.map +1 -1
- package/dist/esm/components/Select/SelectMenu.js +2 -1
- package/dist/esm/components/Select/SelectMenu.js.map +1 -1
- package/dist/esm/components/Select/SelectOption.d.ts.map +1 -1
- package/dist/esm/components/Select/SelectOption.js +6 -1
- package/dist/esm/components/Select/SelectOption.js.map +1 -1
- package/dist/esm/components/Select/SelectToggle.d.ts +3 -2
- package/dist/esm/components/Select/SelectToggle.d.ts.map +1 -1
- package/dist/esm/components/Select/SelectToggle.js +26 -16
- package/dist/esm/components/Select/SelectToggle.js.map +1 -1
- package/dist/esm/components/Select/selectConstants.d.ts +1 -0
- package/dist/esm/components/Select/selectConstants.d.ts.map +1 -1
- package/dist/esm/components/Select/selectConstants.js +1 -0
- package/dist/esm/components/Select/selectConstants.js.map +1 -1
- package/dist/esm/components/Tabs/Tabs.d.ts +2 -5
- package/dist/esm/components/Tabs/Tabs.d.ts.map +1 -1
- package/dist/esm/components/Tabs/Tabs.js +3 -3
- package/dist/esm/components/Tabs/Tabs.js.map +1 -1
- package/dist/esm/helpers/util.d.ts +6 -0
- package/dist/esm/helpers/util.d.ts.map +1 -1
- package/dist/esm/helpers/util.js +12 -0
- package/dist/esm/helpers/util.js.map +1 -1
- package/dist/js/components/Select/Select.d.ts +5 -1
- package/dist/js/components/Select/Select.d.ts.map +1 -1
- package/dist/js/components/Select/Select.js +170 -27
- package/dist/js/components/Select/Select.js.map +1 -1
- package/dist/js/components/Select/SelectMenu.d.ts.map +1 -1
- package/dist/js/components/Select/SelectMenu.js +2 -1
- package/dist/js/components/Select/SelectMenu.js.map +1 -1
- package/dist/js/components/Select/SelectOption.d.ts.map +1 -1
- package/dist/js/components/Select/SelectOption.js +6 -1
- package/dist/js/components/Select/SelectOption.js.map +1 -1
- package/dist/js/components/Select/SelectToggle.d.ts +3 -2
- package/dist/js/components/Select/SelectToggle.d.ts.map +1 -1
- package/dist/js/components/Select/SelectToggle.js +25 -15
- package/dist/js/components/Select/SelectToggle.js.map +1 -1
- package/dist/js/components/Select/selectConstants.d.ts +1 -0
- package/dist/js/components/Select/selectConstants.d.ts.map +1 -1
- package/dist/js/components/Select/selectConstants.js +2 -1
- package/dist/js/components/Select/selectConstants.js.map +1 -1
- package/dist/js/components/Tabs/Tabs.d.ts +2 -5
- package/dist/js/components/Tabs/Tabs.d.ts.map +1 -1
- package/dist/js/components/Tabs/Tabs.js +3 -3
- package/dist/js/components/Tabs/Tabs.js.map +1 -1
- package/dist/js/helpers/util.d.ts +6 -0
- package/dist/js/helpers/util.d.ts.map +1 -1
- package/dist/js/helpers/util.js +14 -1
- package/dist/js/helpers/util.js.map +1 -1
- package/dist/umd/react-core.css +64 -6
- package/dist/umd/react-core.js +218 -47
- package/dist/umd/react-core.min.css +78 -20
- package/dist/umd/react-core.min.js +3 -3
- package/package.json +6 -6
- package/src/components/Select/Select.tsx +166 -26
- package/src/components/Select/SelectMenu.tsx +2 -1
- package/src/components/Select/SelectOption.tsx +5 -1
- package/src/components/Select/SelectToggle.tsx +38 -17
- package/src/components/Select/__tests__/__snapshots__/Select.test.tsx.snap +74 -24
- package/src/components/Select/examples/Select.md +5 -1
- package/src/components/Select/selectConstants.tsx +2 -0
- package/src/components/Tabs/Tabs.tsx +6 -9
- package/src/helpers/util.ts +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.192.
|
|
3
|
+
"version": "4.192.12",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"generate": "node scripts/copyStyles.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@patternfly/react-icons": "^4.43.
|
|
38
|
-
"@patternfly/react-styles": "^4.42.
|
|
39
|
-
"@patternfly/react-tokens": "^4.44.
|
|
37
|
+
"@patternfly/react-icons": "^4.43.12",
|
|
38
|
+
"@patternfly/react-styles": "^4.42.12",
|
|
39
|
+
"@patternfly/react-tokens": "^4.44.12",
|
|
40
40
|
"focus-trap": "6.2.2",
|
|
41
41
|
"react-dropzone": "9.0.0",
|
|
42
42
|
"tippy.js": "5.1.2",
|
|
43
43
|
"tslib": "^2.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@patternfly/patternfly": "4.171.
|
|
46
|
+
"@patternfly/patternfly": "4.171.1",
|
|
47
47
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
48
48
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
49
49
|
"@rollup/plugin-replace": "^3.0.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.8.0 || ^17.0.0",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "8422aef0c69f3f50a7321806c8beeba1ee2df92e"
|
|
64
64
|
}
|
|
@@ -12,7 +12,14 @@ import { SelectMenu } from './SelectMenu';
|
|
|
12
12
|
import { SelectOption, SelectOptionObject } from './SelectOption';
|
|
13
13
|
import { SelectGroup, SelectGroupProps } from './SelectGroup';
|
|
14
14
|
import { SelectToggle } from './SelectToggle';
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
SelectContext,
|
|
17
|
+
SelectVariant,
|
|
18
|
+
SelectPosition,
|
|
19
|
+
SelectDirection,
|
|
20
|
+
KeyTypes,
|
|
21
|
+
SelectFooterTabbableItems
|
|
22
|
+
} from './selectConstants';
|
|
16
23
|
import { Chip, ChipGroup, ChipGroupProps } from '../ChipGroup';
|
|
17
24
|
import { Spinner } from '../Spinner';
|
|
18
25
|
import {
|
|
@@ -24,10 +31,12 @@ import {
|
|
|
24
31
|
PickOptional,
|
|
25
32
|
GenerateId
|
|
26
33
|
} from '../../helpers';
|
|
34
|
+
import { getUniqueId } from '../../helpers/util';
|
|
27
35
|
import { Divider } from '../Divider';
|
|
28
36
|
import { ToggleMenuBaseProps, Popper } from '../../helpers/Popper/Popper';
|
|
29
37
|
import { createRenderableFavorites, extendItemsWithFavorite } from '../../helpers/favorites';
|
|
30
38
|
import { ValidatedOptions } from '../../helpers/constants';
|
|
39
|
+
import { findTabbableElements } from '../../helpers/util';
|
|
31
40
|
|
|
32
41
|
// seed for the aria-labelledby ID
|
|
33
42
|
let currentId = 0;
|
|
@@ -140,6 +149,8 @@ export interface SelectProps
|
|
|
140
149
|
customBadgeText?: string | number;
|
|
141
150
|
/** Prefix for the id of the input in the checkbox select variant*/
|
|
142
151
|
inputIdPrefix?: string;
|
|
152
|
+
/** Value for the typeahead and inline filtering input autocomplete attribute */
|
|
153
|
+
inputAutoComplete?: string;
|
|
143
154
|
/** Optional props to pass to the chip group in the typeaheadmulti variant */
|
|
144
155
|
chipGroupProps?: Omit<ChipGroupProps, 'children' | 'ref'>;
|
|
145
156
|
/** Optional props to render custom chip group in the typeaheadmulti variant */
|
|
@@ -213,6 +224,7 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
213
224
|
inlineFilterPlaceholderText: null,
|
|
214
225
|
customBadgeText: null,
|
|
215
226
|
inputIdPrefix: '',
|
|
227
|
+
inputAutoComplete: navigator.userAgent.match('Chrome') ? getUniqueId('pf-no-autocomplete') : 'off',
|
|
216
228
|
menuAppendTo: 'inline',
|
|
217
229
|
favorites: [] as string[],
|
|
218
230
|
favoritesLabel: 'Favorites',
|
|
@@ -613,9 +625,42 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
613
625
|
}));
|
|
614
626
|
};
|
|
615
627
|
|
|
616
|
-
|
|
628
|
+
switchFocusToFavoriteMenu = () => {
|
|
629
|
+
const { typeaheadCurrIndex, typeaheadStoredIndex } = this.state;
|
|
630
|
+
let indexForFocus = 0;
|
|
631
|
+
|
|
632
|
+
if (typeaheadCurrIndex !== -1) {
|
|
633
|
+
indexForFocus = typeaheadCurrIndex;
|
|
634
|
+
} else if (typeaheadStoredIndex !== -1) {
|
|
635
|
+
indexForFocus = typeaheadStoredIndex;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
if (this.refCollection[indexForFocus] !== null && this.refCollection[indexForFocus][0] !== null) {
|
|
639
|
+
this.refCollection[indexForFocus][0].focus();
|
|
640
|
+
} else {
|
|
641
|
+
this.clearRef.current.focus();
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
this.setState({
|
|
645
|
+
tabbedIntoFavoritesMenu: true,
|
|
646
|
+
typeaheadCurrIndex: -1
|
|
647
|
+
});
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
moveFocusToLastMenuItem = () => {
|
|
651
|
+
const refCollectionLen = this.refCollection.length;
|
|
652
|
+
if (
|
|
653
|
+
refCollectionLen > 0 &&
|
|
654
|
+
this.refCollection[refCollectionLen - 1] !== null &&
|
|
655
|
+
this.refCollection[refCollectionLen - 1][0] !== null
|
|
656
|
+
) {
|
|
657
|
+
this.refCollection[refCollectionLen - 1][0].focus();
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
handleTypeaheadKeys = (position: string, shiftKey: boolean = false) => {
|
|
617
662
|
const { isOpen, onFavorite } = this.props;
|
|
618
|
-
const { typeaheadCurrIndex, tabbedIntoFavoritesMenu
|
|
663
|
+
const { typeaheadCurrIndex, tabbedIntoFavoritesMenu } = this.state;
|
|
619
664
|
const typeaheadActiveChild = this.getTypeaheadActiveChild(typeaheadCurrIndex);
|
|
620
665
|
|
|
621
666
|
if (isOpen) {
|
|
@@ -633,30 +678,110 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
633
678
|
}
|
|
634
679
|
} else if (position === 'tab') {
|
|
635
680
|
if (onFavorite) {
|
|
681
|
+
// if the input has focus, tab to the first item or the last item that was previously focused.
|
|
636
682
|
if (this.inputRef.current === document.activeElement) {
|
|
637
|
-
|
|
638
|
-
if (
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
this.refCollection[indexForFocus][0].focus();
|
|
683
|
+
// If shift is also clicked and there is a footer, tab to the last item in tabbable footer
|
|
684
|
+
if (this.props.footer && shiftKey) {
|
|
685
|
+
const tabbableItems = findTabbableElements(this.footerRef, SelectFooterTabbableItems);
|
|
686
|
+
if (tabbableItems.length > 0) {
|
|
687
|
+
if (tabbableItems[tabbableItems.length - 1]) {
|
|
688
|
+
tabbableItems[tabbableItems.length - 1].focus();
|
|
689
|
+
}
|
|
690
|
+
}
|
|
646
691
|
} else {
|
|
647
|
-
this.
|
|
692
|
+
this.switchFocusToFavoriteMenu();
|
|
648
693
|
}
|
|
649
|
-
|
|
650
|
-
this.setState({
|
|
651
|
-
tabbedIntoFavoritesMenu: true,
|
|
652
|
-
typeaheadCurrIndex: -1
|
|
653
|
-
});
|
|
654
694
|
} else {
|
|
655
|
-
|
|
656
|
-
this.
|
|
695
|
+
// focus is on menu or footer
|
|
696
|
+
if (this.props.footer) {
|
|
697
|
+
let tabbedIntoMenu = false;
|
|
698
|
+
const tabbableItems = findTabbableElements(this.footerRef, SelectFooterTabbableItems);
|
|
699
|
+
if (tabbableItems.length > 0) {
|
|
700
|
+
// if current element is not in footer, tab to first tabbable element in footer,
|
|
701
|
+
// if shift was clicked, tab to input since focus is on menu
|
|
702
|
+
const currentElementIndex = tabbableItems.findIndex((item: any) => item === document.activeElement);
|
|
703
|
+
if (currentElementIndex === -1) {
|
|
704
|
+
if (shiftKey) {
|
|
705
|
+
// currently in menu, shift back to input
|
|
706
|
+
this.inputRef.current.focus();
|
|
707
|
+
} else {
|
|
708
|
+
// currently in menu, tab to first tabbable item in footer
|
|
709
|
+
tabbableItems[0].focus();
|
|
710
|
+
}
|
|
711
|
+
} else {
|
|
712
|
+
// already in footer
|
|
713
|
+
if (shiftKey) {
|
|
714
|
+
// shift to previous item
|
|
715
|
+
if (currentElementIndex === 0) {
|
|
716
|
+
// on first footer item, shift back to menu
|
|
717
|
+
this.switchFocusToFavoriteMenu();
|
|
718
|
+
tabbedIntoMenu = true;
|
|
719
|
+
} else {
|
|
720
|
+
// shift to previous footer item
|
|
721
|
+
tabbableItems[currentElementIndex - 1].focus();
|
|
722
|
+
}
|
|
723
|
+
} else {
|
|
724
|
+
// tab to next tabbable item in footer or to input.
|
|
725
|
+
if (tabbableItems[currentElementIndex + 1]) {
|
|
726
|
+
tabbableItems[currentElementIndex + 1].focus();
|
|
727
|
+
} else {
|
|
728
|
+
this.inputRef.current.focus();
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
} else {
|
|
733
|
+
// no tabbable items in footer, tab to input
|
|
734
|
+
this.inputRef.current.focus();
|
|
735
|
+
tabbedIntoMenu = false;
|
|
736
|
+
}
|
|
737
|
+
this.setState({ tabbedIntoFavoritesMenu: tabbedIntoMenu });
|
|
738
|
+
} else {
|
|
739
|
+
this.inputRef.current.focus();
|
|
740
|
+
this.setState({ tabbedIntoFavoritesMenu: false });
|
|
741
|
+
}
|
|
657
742
|
}
|
|
658
743
|
} else {
|
|
659
|
-
|
|
744
|
+
// Close if there is no footer
|
|
745
|
+
if (!this.props.footer) {
|
|
746
|
+
this.onToggle(false);
|
|
747
|
+
} else {
|
|
748
|
+
// has footer
|
|
749
|
+
const tabbableItems = findTabbableElements(this.footerRef, SelectFooterTabbableItems);
|
|
750
|
+
const currentElementIndex = tabbableItems.findIndex((item: any) => item === document.activeElement);
|
|
751
|
+
if (this.inputRef.current === document.activeElement) {
|
|
752
|
+
if (shiftKey) {
|
|
753
|
+
// close toggle if shift key and tab on input
|
|
754
|
+
this.onToggle(false);
|
|
755
|
+
} else {
|
|
756
|
+
// tab to first tabbable item in footer
|
|
757
|
+
if (tabbableItems[0]) {
|
|
758
|
+
tabbableItems[0].focus();
|
|
759
|
+
} else {
|
|
760
|
+
this.onToggle(false);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
} else {
|
|
764
|
+
// focus is in footer
|
|
765
|
+
if (shiftKey) {
|
|
766
|
+
if (currentElementIndex === 0) {
|
|
767
|
+
// shift tab back to input
|
|
768
|
+
this.inputRef.current.focus();
|
|
769
|
+
} else {
|
|
770
|
+
// shift to previous footer item
|
|
771
|
+
tabbableItems[currentElementIndex - 1].focus();
|
|
772
|
+
}
|
|
773
|
+
} else {
|
|
774
|
+
// tab to next footer item or close tab if last item
|
|
775
|
+
if (tabbableItems[currentElementIndex + 1]) {
|
|
776
|
+
tabbableItems[currentElementIndex + 1].focus();
|
|
777
|
+
} else {
|
|
778
|
+
// no next item, close toggle
|
|
779
|
+
this.onToggle(false);
|
|
780
|
+
this.inputRef.current.focus();
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
660
785
|
}
|
|
661
786
|
} else if (!tabbedIntoFavoritesMenu) {
|
|
662
787
|
if (this.refCollection[0][0] === null) {
|
|
@@ -793,6 +918,7 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
793
918
|
noResultsFoundText,
|
|
794
919
|
customBadgeText,
|
|
795
920
|
inputIdPrefix,
|
|
921
|
+
inputAutoComplete,
|
|
796
922
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
797
923
|
isInputValuePersisted,
|
|
798
924
|
isInputFilterPersisted,
|
|
@@ -856,7 +982,7 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
856
982
|
if (renderableItems.find(item => (item as any)?.key === 'loading') === undefined) {
|
|
857
983
|
if (loadingVariant === 'spinner') {
|
|
858
984
|
renderableItems.push(
|
|
859
|
-
<SelectOption isLoading key="loading" value="loading"
|
|
985
|
+
<SelectOption isLoading key="loading" value="loading">
|
|
860
986
|
<Spinner size="lg" />
|
|
861
987
|
</SelectOption>
|
|
862
988
|
);
|
|
@@ -866,7 +992,6 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
866
992
|
isLoad
|
|
867
993
|
key="loading"
|
|
868
994
|
value={loadingVariant.text}
|
|
869
|
-
isGrouped
|
|
870
995
|
setViewMoreNextIndex={this.setVieMoreNextIndex}
|
|
871
996
|
onClick={loadingVariant?.onClick}
|
|
872
997
|
/>
|
|
@@ -940,6 +1065,20 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
940
1065
|
} else if (event.key === KeyTypes.ArrowRight) {
|
|
941
1066
|
this.handleMenuKeys(0, 0, 'right');
|
|
942
1067
|
event.preventDefault();
|
|
1068
|
+
} else if (event.key === KeyTypes.Tab && variant !== SelectVariant.checkbox && this.props.footer) {
|
|
1069
|
+
// tab to footer or close menu if shift key
|
|
1070
|
+
if (event.shiftKey) {
|
|
1071
|
+
this.onToggle(false);
|
|
1072
|
+
} else {
|
|
1073
|
+
const tabbableItems = findTabbableElements(this.footerRef, SelectFooterTabbableItems);
|
|
1074
|
+
if (tabbableItems.length > 0) {
|
|
1075
|
+
tabbableItems[0].focus();
|
|
1076
|
+
event.stopPropagation();
|
|
1077
|
+
event.preventDefault();
|
|
1078
|
+
} else {
|
|
1079
|
+
this.onToggle(false);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
943
1082
|
} else if (event.key === KeyTypes.Tab && variant === SelectVariant.checkbox) {
|
|
944
1083
|
// More modal-like experience for checkboxes
|
|
945
1084
|
// Let SelectOption handle this
|
|
@@ -953,7 +1092,7 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
953
1092
|
}
|
|
954
1093
|
}}
|
|
955
1094
|
ref={this.filterRef}
|
|
956
|
-
autoComplete=
|
|
1095
|
+
autoComplete={inputAutoComplete}
|
|
957
1096
|
/>
|
|
958
1097
|
</div>
|
|
959
1098
|
<Divider key="inline-filter-divider" />
|
|
@@ -1091,6 +1230,7 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
1091
1230
|
aria-labelledby={`${ariaLabelledBy || ''} ${selectToggleId}`}
|
|
1092
1231
|
aria-label={toggleAriaLabel}
|
|
1093
1232
|
handleTypeaheadKeys={this.handleTypeaheadKeys}
|
|
1233
|
+
moveFocusToLastMenuItem={this.moveFocusToLastMenuItem}
|
|
1094
1234
|
isDisabled={isDisabled}
|
|
1095
1235
|
hasClearButton={hasOnClear}
|
|
1096
1236
|
hasFooter={footer !== undefined}
|
|
@@ -1147,7 +1287,7 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
1147
1287
|
type="text"
|
|
1148
1288
|
onClick={this.onClick}
|
|
1149
1289
|
onChange={this.onChange}
|
|
1150
|
-
autoComplete=
|
|
1290
|
+
autoComplete={inputAutoComplete}
|
|
1151
1291
|
disabled={isDisabled}
|
|
1152
1292
|
ref={this.inputRef}
|
|
1153
1293
|
/>
|
|
@@ -1171,7 +1311,7 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
1171
1311
|
type="text"
|
|
1172
1312
|
onChange={this.onChange}
|
|
1173
1313
|
onClick={this.onClick}
|
|
1174
|
-
autoComplete=
|
|
1314
|
+
autoComplete={inputAutoComplete}
|
|
1175
1315
|
disabled={isDisabled}
|
|
1176
1316
|
ref={this.inputRef}
|
|
1177
1317
|
/>
|
|
@@ -152,7 +152,8 @@ class SelectMenuWithRef extends React.Component<SelectMenuProps> {
|
|
|
152
152
|
isChecked: this.checkForValue(option.props.value, checked),
|
|
153
153
|
sendRef,
|
|
154
154
|
keyHandler,
|
|
155
|
-
index: index
|
|
155
|
+
index: index++,
|
|
156
|
+
isLastOptionBeforeFooter
|
|
156
157
|
})
|
|
157
158
|
)}
|
|
158
159
|
</fieldset>
|
|
@@ -134,7 +134,11 @@ export class SelectOption extends React.Component<SelectOptionProps> {
|
|
|
134
134
|
}
|
|
135
135
|
event.stopPropagation();
|
|
136
136
|
} else {
|
|
137
|
-
|
|
137
|
+
if (event.shiftKey) {
|
|
138
|
+
keyHandler(index, innerIndex, 'up');
|
|
139
|
+
} else {
|
|
140
|
+
keyHandler(index, innerIndex, 'tab');
|
|
141
|
+
}
|
|
138
142
|
}
|
|
139
143
|
}
|
|
140
144
|
event.preventDefault();
|
|
@@ -3,8 +3,9 @@ import styles from '@patternfly/react-styles/css/components/Select/select';
|
|
|
3
3
|
import buttonStyles from '@patternfly/react-styles/css/components/Button/button';
|
|
4
4
|
import { css } from '@patternfly/react-styles';
|
|
5
5
|
import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
|
|
6
|
-
import { KeyTypes, SelectVariant } from './selectConstants';
|
|
6
|
+
import { KeyTypes, SelectVariant, SelectFooterTabbableItems } from './selectConstants';
|
|
7
7
|
import { PickOptional } from '../../helpers/typeUtils';
|
|
8
|
+
import { findTabbableElements } from '../../helpers/util';
|
|
8
9
|
|
|
9
10
|
export interface SelectToggleProps extends React.HTMLProps<HTMLElement> {
|
|
10
11
|
/** HTML ID of dropdown toggle */
|
|
@@ -22,7 +23,9 @@ export interface SelectToggleProps extends React.HTMLProps<HTMLElement> {
|
|
|
22
23
|
/** Callback for toggle close */
|
|
23
24
|
onClose?: () => void;
|
|
24
25
|
/** @hide Internal callback for toggle keyboard navigation */
|
|
25
|
-
handleTypeaheadKeys?: (position: string) => void;
|
|
26
|
+
handleTypeaheadKeys?: (position: string, shiftKey?: boolean) => void;
|
|
27
|
+
/** @hide Internal callback to move focus to last menu item */
|
|
28
|
+
moveFocusToLastMenuItem?: () => void;
|
|
26
29
|
/** Element which wraps toggle */
|
|
27
30
|
parentRef: React.RefObject<HTMLDivElement>;
|
|
28
31
|
/** The menu element */
|
|
@@ -106,16 +109,18 @@ export class SelectToggle extends React.Component<SelectToggleProps> {
|
|
|
106
109
|
}
|
|
107
110
|
};
|
|
108
111
|
|
|
109
|
-
findTabbableFooterElements = () => {
|
|
110
|
-
const tabbable = this.props.footerRef.current.querySelectorAll('input, button, select, textarea, a[href]');
|
|
111
|
-
const list = Array.prototype.filter.call(tabbable, function(item) {
|
|
112
|
-
return item.tabIndex >= '0';
|
|
113
|
-
});
|
|
114
|
-
return list;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
112
|
handleGlobalKeys = (event: KeyboardEvent) => {
|
|
118
|
-
const {
|
|
113
|
+
const {
|
|
114
|
+
parentRef,
|
|
115
|
+
menuRef,
|
|
116
|
+
hasFooter,
|
|
117
|
+
footerRef,
|
|
118
|
+
isOpen,
|
|
119
|
+
variant,
|
|
120
|
+
onToggle,
|
|
121
|
+
onClose,
|
|
122
|
+
moveFocusToLastMenuItem
|
|
123
|
+
} = this.props;
|
|
119
124
|
const escFromToggle = parentRef && parentRef.current && parentRef.current.contains(event.target as Node);
|
|
120
125
|
const escFromWithinMenu =
|
|
121
126
|
menuRef && menuRef.current && menuRef.current.contains && menuRef.current.contains(event.target as Node);
|
|
@@ -124,13 +129,13 @@ export class SelectToggle extends React.Component<SelectToggleProps> {
|
|
|
124
129
|
event.key === KeyTypes.Tab &&
|
|
125
130
|
(variant === SelectVariant.typeahead || variant === SelectVariant.typeaheadMulti)
|
|
126
131
|
) {
|
|
127
|
-
this.props.handleTypeaheadKeys('tab');
|
|
132
|
+
this.props.handleTypeaheadKeys('tab', event.shiftKey);
|
|
128
133
|
event.preventDefault();
|
|
129
134
|
return;
|
|
130
135
|
}
|
|
131
136
|
|
|
132
137
|
if (isOpen && event.key === KeyTypes.Tab && hasFooter) {
|
|
133
|
-
const tabbableItems =
|
|
138
|
+
const tabbableItems = findTabbableElements(footerRef, SelectFooterTabbableItems);
|
|
134
139
|
|
|
135
140
|
// If no tabbable item in footer close select
|
|
136
141
|
if (tabbableItems.length <= 0) {
|
|
@@ -139,14 +144,29 @@ export class SelectToggle extends React.Component<SelectToggleProps> {
|
|
|
139
144
|
this.toggle.current.focus();
|
|
140
145
|
return;
|
|
141
146
|
} else {
|
|
142
|
-
// if current element is not in footer, tab to first tabbable element in footer
|
|
143
|
-
const currentElementIndex = tabbableItems.findIndex(item => item === document.activeElement);
|
|
147
|
+
// if current element is not in footer, tab to first tabbable element in footer, or close if shift clicked
|
|
148
|
+
const currentElementIndex = tabbableItems.findIndex((item: any) => item === document.activeElement);
|
|
144
149
|
if (currentElementIndex === -1) {
|
|
145
|
-
|
|
146
|
-
|
|
150
|
+
if (event.shiftKey) {
|
|
151
|
+
if (variant !== 'checkbox') {
|
|
152
|
+
// only close non checkbox variation on shift clicked
|
|
153
|
+
onToggle(false);
|
|
154
|
+
onClose();
|
|
155
|
+
this.toggle.current.focus();
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
// tab to footer
|
|
159
|
+
tabbableItems[0].focus();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
147
162
|
}
|
|
148
163
|
// Current element is in footer.
|
|
149
164
|
if (event.shiftKey) {
|
|
165
|
+
// Move focus back to menuif current tab index is 0
|
|
166
|
+
if (currentElementIndex === 0) {
|
|
167
|
+
moveFocusToLastMenuItem();
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
}
|
|
150
170
|
return;
|
|
151
171
|
}
|
|
152
172
|
// Tab to next element in footer or close if there are none
|
|
@@ -225,6 +245,7 @@ export class SelectToggle extends React.Component<SelectToggleProps> {
|
|
|
225
245
|
onClose,
|
|
226
246
|
onClickTypeaheadToggleButton,
|
|
227
247
|
handleTypeaheadKeys,
|
|
248
|
+
moveFocusToLastMenuItem,
|
|
228
249
|
parentRef,
|
|
229
250
|
menuRef,
|
|
230
251
|
id,
|