Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const ContextSelectorBasic: React.FunctionComponent = () => {
setSearchValue(value);
};

const onSearchButtonClick = (_event: React.SyntheticEvent<HTMLButtonElement>) => {
const onSearchButtonClick = () => {
const filtered =
searchValue === ''
? items
Expand All @@ -71,11 +71,11 @@ export const ContextSelectorBasic: React.FunctionComponent = () => {
screenReaderLabel="Selected Project:"
>
{filteredItems.map((item, index) => {
const [text = null, href = null, isDisabled] =
typeof item === 'string' ? [item, null, false] : [item.text, item.href, item.isDisabled];
const [text = null, href = undefined, isDisabled] =
typeof item === 'string' ? [item, undefined, false] : [item.text, item.href, item.isDisabled];
return (
<ContextSelectorItem key={index} href={href} isDisabled={isDisabled}>
{text || item}
{text}
</ContextSelectorItem>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const ContextSelectorPlainText: React.FunctionComponent = () => {
setSearchValue(value);
};

const onSearchButtonClick = (_event: React.SyntheticEvent<HTMLButtonElement>) => {
const onSearchButtonClick = () => {
const filtered =
searchValue === ''
? items
Expand All @@ -72,8 +72,8 @@ export const ContextSelectorPlainText: React.FunctionComponent = () => {
isText
>
{filteredItems.map((item, index) => {
const [text, href = null, isDisabled = false] =
typeof item === 'string' ? [item, null, false] : [item.text, item.href, item.isDisabled];
const [text, href = undefined, isDisabled = false] =
typeof item === 'string' ? [item, undefined, false] : [item.text, item.href, item.isDisabled];
return (
<ContextSelectorItem key={index} href={href} isDisabled={isDisabled}>
{text}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const ContextSelectorWithFooter: React.FunctionComponent = () => {
setSearchValue(value);
};

const onSearchButtonClick = (_event: React.SyntheticEvent<HTMLButtonElement>) => {
const onSearchButtonClick = () => {
const filtered =
searchValue === ''
? items
Expand Down Expand Up @@ -78,11 +78,11 @@ export const ContextSelectorWithFooter: React.FunctionComponent = () => {
}
>
{filteredItems.map((item, index) => {
const [text = null, href = null, isDisabled] =
typeof item === 'string' ? [item, null, false] : [item.text, item.href, item.isDisabled];
const [text = null, href = undefined, isDisabled] =
typeof item === 'string' ? [item, undefined, false] : [item.text, item.href, item.isDisabled];
return (
<ContextSelectorItem key={index} href={href} isDisabled={isDisabled}>
{text || item}
{text}
</ContextSelectorItem>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-d
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
import PficonSortCommonAscIcon from '@patternfly/react-icons/dist/esm/icons/pficon-sort-common-asc-icon';

interface Option {
text: string;
selected: boolean;
isVisible: boolean;
}

export const DualListSelectorComposable: React.FunctionComponent = () => {
const [availableOptions, setAvailableOptions] = React.useState([
const [availableOptions, setAvailableOptions] = React.useState<Option[]>([
{ text: 'Apple', selected: false, isVisible: true },
{ text: 'Banana', selected: false, isVisible: true },
{ text: 'Pineapple', selected: false, isVisible: true },
Expand All @@ -26,7 +32,7 @@ export const DualListSelectorComposable: React.FunctionComponent = () => {
{ text: 'Peach', selected: false, isVisible: true },
{ text: 'Strawberry', selected: false, isVisible: true }
]);
const [chosenOptions, setChosenOptions] = React.useState([]);
const [chosenOptions, setChosenOptions] = React.useState<Option[]>([]);
const [availableFilter, setAvailableFilter] = React.useState('');
const [chosenFilter, setChosenFilter] = React.useState('');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ import {
DualListSelectorList,
DualListSelectorListItem,
DualListSelectorControlsWrapper,
DualListSelectorControl
DualListSelectorControl,
DraggableItemPosition
} from '@patternfly/react-core';
import AngleDoubleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-left-icon';
import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-right-icon';
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';

interface SourceType {
droppableId: string;
index: number;
}

interface DestinationType extends SourceType {}

export const DualListSelectorComposableDragDrop: React.FunctionComponent = () => {
const [ignoreNextOptionSelect, setIgnoreNextOptionSelect] = React.useState(false);
const [availableOptions, setAvailableOptions] = React.useState([
Expand Down Expand Up @@ -87,7 +81,7 @@ export const DualListSelectorComposableDragDrop: React.FunctionComponent = () =>
}
};

const onDrop = (source: SourceType, dest: DestinationType) => {
const onDrop = (source: DraggableItemPosition, dest?: DraggableItemPosition) => {
if (dest) {
const newList = [...chosenOptions];
const [removed] = newList.splice(source.index, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const DualListSelectorComposableTree: React.FunctionComponent<ExampleProp
if (!node.children || !node.children.length) {
return [node.id];
} else {
let childrenIds = [];
let childrenIds: string[] = [];
node.children.forEach(child => {
childrenIds = [...childrenIds, ...getDescendantLeafIds(child)];
});
Expand All @@ -77,7 +77,7 @@ export const DualListSelectorComposableTree: React.FunctionComponent<ExampleProp
// Builds a map of child leaf nodes by node id - memoized so that it only rebuilds the list if the data changes.
const { memoizedLeavesById, memoizedAllLeaves, memoizedNodeText } = React.useMemo(() => {
let leavesById = {};
let allLeaves = [];
let allLeaves: string[] = [];
let nodeTexts = {};
data.forEach(foodNode => {
nodeTexts = { ...nodeTexts, ...buildTextById(foodNode) };
Expand Down Expand Up @@ -129,7 +129,7 @@ export const DualListSelectorComposableTree: React.FunctionComponent<ExampleProp
return true;
}
if (areSomeDescendantsSelected(node, isChosen)) {
return null;
return false;
}
return false;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { DualListSelector } from '@patternfly/react-core';
import { DualListSelector, DualListSelectorTreeItemData } from '@patternfly/react-core';

export const DualListSelectorTreeExample: React.FunctionComponent = () => {
const [availableOptions, setAvailableOptions] = React.useState<React.ReactNode[]>([
const [availableOptions, setAvailableOptions] = React.useState<DualListSelectorTreeItemData[]>([
{
id: 'F1',
text: 'Folder 1',
Expand Down Expand Up @@ -38,7 +38,7 @@ export const DualListSelectorTreeExample: React.FunctionComponent = () => {
}
]);

const [chosenOptions, setChosenOptions] = React.useState<React.ReactNode[]>([
const [chosenOptions, setChosenOptions] = React.useState<DualListSelectorTreeItemData[]>([
{
id: 'CF1',
text: 'Chosen Folder 1',
Expand Down Expand Up @@ -73,7 +73,10 @@ export const DualListSelectorTreeExample: React.FunctionComponent = () => {
}
]);

const onListChange = (newAvailableOptions: React.ReactNode[], newChosenOptions: React.ReactNode[]) => {
const onListChange = (
newAvailableOptions: DualListSelectorTreeItemData[],
newChosenOptions: DualListSelectorTreeItemData[]
) => {
setAvailableOptions(newAvailableOptions.sort());
setChosenOptions(newChosenOptions.sort());
};
Expand All @@ -84,7 +87,7 @@ export const DualListSelectorTreeExample: React.FunctionComponent = () => {
isTree
availableOptions={availableOptions}
chosenOptions={chosenOptions}
onListChange={onListChange}
onListChange={onListChange as any}
id="dual-list-selector-tree"
/>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/react-core/src/components/MenuToggle/MenuToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class MenuToggleBase extends React.Component<MenuToggleProps> {
<>
{icon && <span className={css(styles.menuToggleIcon)}>{icon}</span>}
{isTypeahead ? children : <span className={css(styles.menuToggleText)}>{children}</span>}
{badge && <span className={css(styles.menuToggleCount)}>{badge}</span>}
{React.isValidElement(badge) && <span className={css(styles.menuToggleCount)}>{badge}</span>}
{isTypeahead ? (
<button
type="button"
Expand Down Expand Up @@ -166,7 +166,7 @@ export class MenuToggleBase extends React.Component<MenuToggleProps> {
}
}

export const MenuToggle = React.forwardRef((props: MenuToggleProps, ref: React.Ref<MenuToggleElement>) => (
export const MenuToggle = React.forwardRef<MenuToggleElement, MenuToggleProps>((props, ref) => (
<MenuToggleBase innerRef={ref} {...props} />
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
export const ComposableActionsMenu: React.FunctionComponent = () => {
const [isOpen, setIsOpen] = React.useState<boolean>(false);
const [selectedItems, setSelectedItems] = React.useState<number[]>([]);
const toggleRef = React.useRef<HTMLButtonElement>();
const menuRef = React.useRef<HTMLDivElement>();
const containerRef = React.useRef<HTMLDivElement>();
const toggleRef = React.useRef<HTMLButtonElement>(null);
const menuRef = React.useRef<HTMLDivElement>(null);
const containerRef = React.useRef<HTMLDivElement>(null);

const handleMenuKeys = (event: KeyboardEvent) => {
if (isOpen && menuRef.current.contains(event.target as Node)) {
if (isOpen && menuRef.current?.contains(event.target as Node)) {
if (event.key === 'Escape' || event.key === 'Tab') {
setIsOpen(!isOpen);
toggleRef.current.focus();
toggleRef.current?.focus();
}
}
};

const handleClickOutside = (event: MouseEvent) => {
if (isOpen && !menuRef.current.contains(event.target as Node)) {
if (isOpen && !menuRef.current?.contains(event.target as Node)) {
setIsOpen(false);
}
};
Expand All @@ -36,7 +36,11 @@ export const ComposableActionsMenu: React.FunctionComponent = () => {
};
}, [isOpen, menuRef]);

const onSelect = (ev: React.MouseEvent<Element, MouseEvent>, itemId: number) => {
const onSelect = (event?: React.MouseEvent, itemId?: string | number) => {
if (typeof itemId === 'string' || typeof itemId === 'undefined') {
return;
}

if (selectedItems.includes(itemId)) {
setSelectedItems(selectedItems.filter(id => id !== itemId));
} else {
Expand Down Expand Up @@ -125,7 +129,7 @@ export const ComposableActionsMenu: React.FunctionComponent = () => {
trigger={toggle}
popper={menu}
isVisible={isOpen}
appendTo={containerRef.current}
appendTo={containerRef.current || undefined}
popperMatchesTriggerWidth={false}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ export const ComposableApplicationLauncher: React.FunctionComponent = () => {
const [refFullOptions, setRefFullOptions] = React.useState<Element[]>();
const [favorites, setFavorites] = React.useState<string[]>([]);
const [filteredIds, setFilteredIds] = React.useState<string[]>(['*']);
const menuRef = React.useRef<HTMLDivElement>();
const toggleRef = React.useRef<HTMLButtonElement>();
const containerRef = React.useRef<HTMLDivElement>();
const menuRef = React.useRef<HTMLDivElement>(null);
const toggleRef = React.useRef<HTMLButtonElement>(null);
const containerRef = React.useRef<HTMLDivElement>(null);

const handleMenuKeys = (event: KeyboardEvent) => {
if (!isOpen) {
return;
}
if (menuRef.current.contains(event.target as Node) || toggleRef.current.contains(event.target as Node)) {
if (menuRef.current?.contains(event.target as Node) || toggleRef.current?.contains(event.target as Node)) {
if (event.key === 'Escape') {
setIsOpen(!isOpen);
toggleRef.current.focus();
toggleRef.current?.focus();
}
}
};

const handleClickOutside = (event: MouseEvent) => {
if (isOpen && !menuRef.current.contains(event.target as Node)) {
if (isOpen && !menuRef.current?.contains(event.target as Node)) {
setIsOpen(false);
}
};
Expand Down Expand Up @@ -132,7 +132,7 @@ export const ComposableApplicationLauncher: React.FunctionComponent = () => {
];

const createFavorites = (favIds: string[]) => {
const favorites = [];
const favorites: unknown[] = [];

menuItems.forEach(item => {
if (item.type === MenuList) {
Expand Down Expand Up @@ -219,9 +219,10 @@ export const ComposableApplicationLauncher: React.FunctionComponent = () => {
return;
}

const filteredIds = refFullOptions
.filter(item => (item as HTMLElement).innerText.toLowerCase().includes(textValue.toString().toLowerCase()))
.map(item => item.id);
const filteredIds =
refFullOptions
?.filter(item => (item as HTMLElement).innerText.toLowerCase().includes(textValue.toString().toLowerCase()))
.map(item => item.id) || [];
setFilteredIds(filteredIds);
};

Expand Down Expand Up @@ -275,7 +276,7 @@ export const ComposableApplicationLauncher: React.FunctionComponent = () => {
popper={menu}
isVisible={isOpen}
popperMatchesTriggerWidth={false}
appendTo={containerRef.current}
appendTo={containerRef.current || undefined}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,37 @@ export const ComposableContextSelector: React.FunctionComponent = () => {
'Azure 2'
];
const [isOpen, setIsOpen] = React.useState<boolean>(false);
const [selected, setSelected] = React.useState<ItemData | string>(
typeof items[0] === 'string' ? items[0] : items[0].text
);
const [selected, setSelected] = React.useState(typeof items[0] === 'string' ? items[0] : items[0].text);
const [filteredItems, setFilteredItems] = React.useState<ItemArrayType>(items);
const [searchInputValue, setSearchInputValue] = React.useState<string>('');
const menuRef = React.useRef<HTMLDivElement>();
const toggleRef = React.useRef<HTMLButtonElement>();
const menuFooterBtnRef = React.useRef<HTMLButtonElement>();
const containerRef = React.useRef<HTMLDivElement>();
const menuRef = React.useRef<HTMLDivElement>(null);
const toggleRef = React.useRef<HTMLButtonElement>(null);
const menuFooterBtnRef = React.useRef<HTMLButtonElement>(null);
const containerRef = React.useRef<HTMLDivElement>(null);

const handleMenuKeys = (event: KeyboardEvent) => {
if (!isOpen) {
return;
}
if (menuFooterBtnRef.current.contains(event.target as Node)) {
if (menuFooterBtnRef.current?.contains(event.target as Node)) {
if (event.key === 'Tab') {
if (event.shiftKey) {
return;
}
setIsOpen(!isOpen);
toggleRef.current.focus();
toggleRef.current?.focus();
}
}
if (menuRef.current.contains(event.target as Node)) {
if (menuRef.current?.contains(event.target as Node)) {
if (event.key === 'Escape') {
setIsOpen(!isOpen);
toggleRef.current.focus();
toggleRef.current?.focus();
}
}
};

const handleClickOutside = (event: MouseEvent) => {
if (isOpen && !menuRef.current.contains(event.target as Node)) {
if (isOpen && !menuRef.current?.contains(event.target as Node)) {
setIsOpen(false);
}
};
Expand Down
Loading