From 9a2bc34b562da86b5936f50f66b5cad50ce8166f Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Thu, 21 Apr 2022 18:13:50 +0200 Subject: [PATCH] Add correct types for class components using context API --- packages/react-core/src/components/Dropdown/DropdownMenu.tsx | 1 + packages/react-core/src/components/Menu/Menu.tsx | 1 + packages/react-core/src/components/Nav/NavList.tsx | 2 +- .../src/components/Toolbar/ToolbarExpandableContent.tsx | 3 ++- packages/react-core/src/components/Toolbar/ToolbarFilter.tsx | 3 ++- packages/react-core/src/components/Toolbar/ToolbarUtils.tsx | 2 +- packages/react-topology/src/components/defs/SVGDefsSetter.tsx | 1 + 7 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/react-core/src/components/Dropdown/DropdownMenu.tsx b/packages/react-core/src/components/Dropdown/DropdownMenu.tsx index 89e049ddae2..8f2db821021 100644 --- a/packages/react-core/src/components/Dropdown/DropdownMenu.tsx +++ b/packages/react-core/src/components/Dropdown/DropdownMenu.tsx @@ -45,6 +45,7 @@ export interface DropdownMenuItem extends React.HTMLAttributes { export class DropdownMenu extends React.Component { static displayName = 'DropdownMenu'; + context!: React.ContextType; refsCollection = [] as HTMLElement[][]; static defaultProps: DropdownMenuProps = { diff --git a/packages/react-core/src/components/Menu/Menu.tsx b/packages/react-core/src/components/Menu/Menu.tsx index b9e6bac329b..232bdb5bf50 100644 --- a/packages/react-core/src/components/Menu/Menu.tsx +++ b/packages/react-core/src/components/Menu/Menu.tsx @@ -72,6 +72,7 @@ export interface MenuState { class MenuBase extends React.Component { static displayName = 'Menu'; static contextType = MenuContext; + context!: React.ContextType; private menuRef = React.createRef(); private activeMenu = null as Element; static defaultProps: MenuProps = { diff --git a/packages/react-core/src/components/Nav/NavList.tsx b/packages/react-core/src/components/Nav/NavList.tsx index 8c4f3905aba..4d1f9dab3bd 100644 --- a/packages/react-core/src/components/Nav/NavList.tsx +++ b/packages/react-core/src/components/Nav/NavList.tsx @@ -23,7 +23,7 @@ export interface NavListProps export class NavList extends React.Component { static displayName = 'NavList'; static contextType = NavContext; - + context!: React.ContextType; static defaultProps: NavListProps = { ariaLeftScroll: 'Scroll left', ariaRightScroll: 'Scroll right' diff --git a/packages/react-core/src/components/Toolbar/ToolbarExpandableContent.tsx b/packages/react-core/src/components/Toolbar/ToolbarExpandableContent.tsx index 6317934a105..1bef7ee02ac 100644 --- a/packages/react-core/src/components/Toolbar/ToolbarExpandableContent.tsx +++ b/packages/react-core/src/components/Toolbar/ToolbarExpandableContent.tsx @@ -28,7 +28,8 @@ export interface ToolbarExpandableContentProps extends React.HTMLProps { static displayName = 'ToolbarExpandableContent'; - static contextType: any = ToolbarContext; + static contextType = ToolbarContext; + context!: React.ContextType; static defaultProps: PickOptional = { isExpanded: false, clearFiltersButtonText: 'Clear all filters' diff --git a/packages/react-core/src/components/Toolbar/ToolbarFilter.tsx b/packages/react-core/src/components/Toolbar/ToolbarFilter.tsx index f19cb765a8f..5e7c85044b2 100644 --- a/packages/react-core/src/components/Toolbar/ToolbarFilter.tsx +++ b/packages/react-core/src/components/Toolbar/ToolbarFilter.tsx @@ -45,7 +45,8 @@ interface ToolbarFilterState { export class ToolbarFilter extends React.Component { static displayName = 'ToolbarFilter'; - static contextType: any = ToolbarContext; + static contextType = ToolbarContext; + context!: React.ContextType; static defaultProps: PickOptional = { chips: [] as (string | ToolbarChip)[], showToolbarItem: true diff --git a/packages/react-core/src/components/Toolbar/ToolbarUtils.tsx b/packages/react-core/src/components/Toolbar/ToolbarUtils.tsx index c178c0bbdc7..9ee37c99f85 100644 --- a/packages/react-core/src/components/Toolbar/ToolbarUtils.tsx +++ b/packages/react-core/src/components/Toolbar/ToolbarUtils.tsx @@ -5,7 +5,7 @@ import globalBreakpointLg from '@patternfly/react-tokens/dist/esm/global_breakpo import globalBreakpointXl from '@patternfly/react-tokens/dist/esm/global_breakpoint_xl'; import globalBreakpoint2xl from '@patternfly/react-tokens/dist/esm/global_breakpoint_2xl'; -interface ToolbarContextProps { +export interface ToolbarContextProps { isExpanded: boolean; toggleIsExpanded: () => void; chipGroupContentRef: RefObject; diff --git a/packages/react-topology/src/components/defs/SVGDefsSetter.tsx b/packages/react-topology/src/components/defs/SVGDefsSetter.tsx index 1e471645f99..b7b7fe032f9 100644 --- a/packages/react-topology/src/components/defs/SVGDefsSetter.tsx +++ b/packages/react-topology/src/components/defs/SVGDefsSetter.tsx @@ -4,6 +4,7 @@ import { SVGDefsSetterProps } from './SVGDefs'; export class SVGDefsSetter extends React.Component { static displayName = 'SVGDefsSetter'; static contextType = SVGDefsContext; + context!: React.ContextType; componentDidMount() { const { addDef, id, children } = this.props; addDef(id, children);