Skip to content

Commit

Permalink
use stricter types
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolethoen committed Jan 19, 2022
1 parent 6a6cb39 commit f648ce2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ComposableActionsMenu: React.FunctionComponent = () => {
};
}, [isOpen, menuRef]);

const onSelect = (event: React.MouseEvent, itemId: number) => {
const onSelect = (ev: React.MouseEvent<Element, MouseEvent>, itemId: number) => {
if (selectedItems.includes(itemId)) {
setSelectedItems(selectedItems.filter(id => id !== itemId));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const ComposableContextSelector: React.FunctionComponent = () => {
</MenuToggle>
);

const onSelect = (event: React.MouseEvent, itemId: string) => {
const onSelect = (ev: React.MouseEvent<Element, MouseEvent>, itemId: string) => {
setSelected(itemId);
setIsOpen(!isOpen);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export const ComposableDropdwnVariants: React.FunctionComponent = () => {
const menuRef = React.useRef<HTMLDivElement>();
const toggleRef = React.useRef<HTMLButtonElement>();

const handleToggleSwitch = (selected: boolean, e: React.MouseEvent) => {
const handleToggleSwitch = (selected: boolean, e: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent) => {
setToggleSelected(e.currentTarget.id);
};

const handleMenuKeys = (event: KeyboardEvent) => {
if (isOpen && menuRef.current.contains(event.target as Node)) {
if (isOpen && menuRef && menuRef.current && menuRef.current.contains(event.target as Node)) {
if (event.key === 'Escape' || event.key === 'Tab') {
setIsOpen(!isOpen);
toggleRef.current.focus();
Expand Down Expand Up @@ -57,14 +57,14 @@ export const ComposableDropdwnVariants: React.FunctionComponent = () => {
ev.stopPropagation(); // Stop handleClickOutside from handling
setTimeout(() => {
if (menuRef.current) {
const firstElement = menuRef.current.querySelector('li > button,input:not(:disabled)');
const firstElement = menuRef.current.querySelector('li > button,input:not(:disabled),a');
firstElement && (firstElement as HTMLElement).focus();
}
}, 0);
setIsOpen(!isOpen);
};

const onSelect = (ev: React.MouseEvent, itemId: string) => {
const onSelect = (ev: React.MouseEvent<Element, MouseEvent>, itemId: string) => {
// eslint-disable-next-line no-console
console.log(`Menu item ${itemId} selected`);
setIsOpen(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { MenuToggle, Menu, MenuContent, MenuList, MenuItem, Popper } from '@patternfly/react-core';

// eslint-disable-next-line no-console
const onSelect = (event: React.MouseEvent, itemId: string) => console.log('selected', itemId);
const onSelect = (ev: React.MouseEvent<Element, MouseEvent>, itemId: string) => console.log('selected', itemId);

interface FlyoutMenuProps {
children?: React.ReactElement;
Expand Down

0 comments on commit f648ce2

Please sign in to comment.