From c53c3c0622a248d54d35a4164e60ca2cf1f09bf9 Mon Sep 17 00:00:00 2001 From: mfrances Date: Mon, 12 Feb 2024 14:25:47 -0500 Subject: [PATCH] rm unnecessary funct and update tests --- .../DualListSelectorContext.ts | 1 - .../DualListSelector/DualListSelectorList.tsx | 21 +------- .../DualListSelectorListItem.tsx | 2 +- .../DualListSelectorListWrapper.tsx | 15 ++---- .../__tests__/DualListSelector.test.tsx | 15 ++---- .../DualListSelector.test.tsx.snap | 49 +++++++++++++++++-- 6 files changed, 57 insertions(+), 46 deletions(-) diff --git a/packages/react-core/src/next/components/DualListSelector/DualListSelectorContext.ts b/packages/react-core/src/next/components/DualListSelector/DualListSelectorContext.ts index 27b1ed1eff2..3eccc9a0dc6 100644 --- a/packages/react-core/src/next/components/DualListSelector/DualListSelectorContext.ts +++ b/packages/react-core/src/next/components/DualListSelector/DualListSelectorContext.ts @@ -12,7 +12,6 @@ export const DualListSelectorListContext = React.createContext<{ displayOption?: (option: React.ReactNode) => boolean; selectedOptions?: string[] | number[]; id?: string; - onOptionSelect?: (e: React.MouseEvent | React.ChangeEvent | React.KeyboardEvent, index: number, id: string) => void; options?: React.ReactNode[]; isDisabled?: boolean; }>({}); diff --git a/packages/react-core/src/next/components/DualListSelector/DualListSelectorList.tsx b/packages/react-core/src/next/components/DualListSelector/DualListSelectorList.tsx index bd565a36b07..13d00467e6b 100644 --- a/packages/react-core/src/next/components/DualListSelector/DualListSelectorList.tsx +++ b/packages/react-core/src/next/components/DualListSelector/DualListSelectorList.tsx @@ -15,24 +15,8 @@ export const DualListSelectorList: React.FunctionComponent { - const { - setFocusedOption, - isTree, - ariaLabelledBy, - focusedOption, - displayOption, - selectedOptions, - id, - onOptionSelect, - options, - isDisabled - } = React.useContext(DualListSelectorListContext); - - // only called when options are passed via options prop - const onOptionClick = (e: React.MouseEvent | React.ChangeEvent | React.KeyboardEvent, index: number, id: string) => { - setFocusedOption(id); - onOptionSelect(e, index, id); - }; + const { isTree, ariaLabelledBy, focusedOption, displayOption, selectedOptions, id, options, isDisabled } = + React.useContext(DualListSelectorListContext); const hasOptions = () => options.length !== 0 || (children !== undefined && (children as React.ReactNode[]).length !== 0); @@ -58,7 +42,6 @@ export const DualListSelectorList: React.FunctionComponent onOptionClick(e, index, id)} orderIndex={index} isDisabled={isDisabled} > diff --git a/packages/react-core/src/next/components/DualListSelector/DualListSelectorListItem.tsx b/packages/react-core/src/next/components/DualListSelector/DualListSelectorListItem.tsx index b52d2d85c2a..8e25b149aa3 100644 --- a/packages/react-core/src/next/components/DualListSelector/DualListSelectorListItem.tsx +++ b/packages/react-core/src/next/components/DualListSelector/DualListSelectorListItem.tsx @@ -17,7 +17,7 @@ export interface DualListSelectorListItemProps extends React.HTMLProps void; /** ID of the option. */ id?: string; diff --git a/packages/react-core/src/next/components/DualListSelector/DualListSelectorListWrapper.tsx b/packages/react-core/src/next/components/DualListSelector/DualListSelectorListWrapper.tsx index f704eb9c971..9f856424850 100644 --- a/packages/react-core/src/next/components/DualListSelector/DualListSelectorListWrapper.tsx +++ b/packages/react-core/src/next/components/DualListSelector/DualListSelectorListWrapper.tsx @@ -8,11 +8,11 @@ import { DualListSelectorContext, DualListSelectorListContext } from './DualList export interface DualListSelectorListWrapperProps extends React.HTMLProps { /** Additional classes applied to the dual list selector. */ className?: string; - /** Anything that can be rendered inside of the list */ + /** Anything that can be rendered inside of the list. */ children?: React.ReactNode; - /** ID of the dual list selector list */ + /** ID of the dual list selector list. */ id?: string; - /** Accessibly label for the list */ + /** Accessibly label for the list. */ 'aria-labelledby': string; /** @hide forwarded ref */ innerRef?: React.RefObject; @@ -20,9 +20,7 @@ export interface DualListSelectorListWrapperProps extends React.HTMLProps void; - /** @hide Function to determine if an option should be displayed depending on a dynamically built filter value */ + /** @hide Function to determine if an option should be displayed depending on a custom filter value. */ displayOption?: (option: React.ReactNode) => boolean; /** Flag indicating whether the component is disabled. */ isDisabled?: boolean; @@ -35,7 +33,6 @@ export const DualListSelectorListWrapperBase: React.FunctionComponent { if ( !menuRef.current || @@ -109,7 +105,6 @@ export const DualListSelectorListWrapperBase: React.FunctionComponent diff --git a/packages/react-core/src/next/components/DualListSelector/__tests__/DualListSelector.test.tsx b/packages/react-core/src/next/components/DualListSelector/__tests__/DualListSelector.test.tsx index 7ee0425c210..c9d3fb38e8d 100644 --- a/packages/react-core/src/next/components/DualListSelector/__tests__/DualListSelector.test.tsx +++ b/packages/react-core/src/next/components/DualListSelector/__tests__/DualListSelector.test.tsx @@ -1,31 +1,26 @@ import { render } from '@testing-library/react'; import { DualListSelectorPane } from '../../DualListSelector'; +import { SearchInput } from '../../../../components/SearchInput'; import React from 'react'; describe('DualListSelector', () => { test('basic', () => { - const { asFragment } = render(); + const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('with search inputs', () => { - const { asFragment } = render( - - ); + const { asFragment } = render(} />); expect(asFragment()).toMatchSnapshot(); }); test('with custom status', () => { - const { asFragment } = render( - - ); + const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('basic with disabled controls', () => { - const { asFragment } = render( - - ); + const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); }); diff --git a/packages/react-core/src/next/components/DualListSelector/__tests__/__snapshots__/DualListSelector.test.tsx.snap b/packages/react-core/src/next/components/DualListSelector/__tests__/__snapshots__/DualListSelector.test.tsx.snap index e0220647955..f0f397aa937 100644 --- a/packages/react-core/src/next/components/DualListSelector/__tests__/__snapshots__/DualListSelector.test.tsx.snap +++ b/packages/react-core/src/next/components/DualListSelector/__tests__/__snapshots__/DualListSelector.test.tsx.snap @@ -4,7 +4,6 @@ exports[`DualListSelector basic 1`] = `
Test status1
@@ -68,8 +65,50 @@ exports[`DualListSelector with search inputs 1`] = `
+
+
+
+
+ + + + + + +
+
+
+