diff --git a/packages/react-core/src/components/Select/Select.tsx b/packages/react-core/src/components/Select/Select.tsx index 7135dea19e7..3e8be9beaf7 100644 --- a/packages/react-core/src/components/Select/Select.tsx +++ b/packages/react-core/src/components/Select/Select.tsx @@ -44,6 +44,8 @@ export interface SelectProps noResultsFoundText?: string; /** Selected item for single select variant. Array of selected items for multi select variants. */ selections?: string | SelectOptionObject | (string | SelectOptionObject)[]; + /** Flag indicating if selection badge should be hidden for checkbox variant,default false */ + isCheckboxSelectionBadgeHidden?: boolean; /** Id for select toggle element */ toggleId?: string; /** Adds accessible text to Select */ @@ -362,6 +364,7 @@ class Select extends React.Component {toggleIcon && {toggleIcon}} {placeholderText} - {selections && (Array.isArray(selections) && selections.length > 0) && ( -
- {selections.length} -
- )} + {!isCheckboxSelectionBadgeHidden && + selections && + (Array.isArray(selections) && selections.length > 0) && ( +
+ {selections.length} +
+ )} {hasOnClear && hasAnySelections && clearBtn} diff --git a/packages/react-core/src/components/Select/__tests__/Select.test.tsx b/packages/react-core/src/components/Select/__tests__/Select.test.tsx index 300fdcf2fb3..fe56424e5c4 100644 --- a/packages/react-core/src/components/Select/__tests__/Select.test.tsx +++ b/packages/react-core/src/components/Select/__tests__/Select.test.tsx @@ -46,7 +46,8 @@ describe('select', () => { describe('single select', () => { test('renders closed successfully', () => { const view = mount( - {selectOptions} ); @@ -55,7 +56,8 @@ describe('select', () => { test('renders disabled successfully', () => { const view = mount( - {selectOptions} ); @@ -64,7 +66,8 @@ describe('select', () => { test('renders expanded successfully', () => { const view = mount( - {selectOptions} ); @@ -72,7 +75,8 @@ describe('select', () => { }); test('renders expanded successfully with custom objects', () => { const view = mount( - {selectOptionsCustom} ); @@ -80,9 +84,10 @@ describe('select', () => { }); }); - test('renders up drection successfully', () => { + test('renders up direction successfully', () => { const view = mount( - {selectOptions} ); @@ -106,6 +111,7 @@ describe('select', () => { }; const view = mount( + @@ -136,7 +142,25 @@ describe('select', () => { describe('checkbox select', () => { test('renders closed successfully', () => { const view = mount( - + {selectOptions} + + ); + expect(view).toMatchSnapshot(); + }); + + test('renders checkbox select selections properly', () => { + const view = mount( + + ); + expect(view).toMatchSnapshot(); + }); + + test('renders checkbox select selections properly when isCheckboxSelectionBadgeHidden is true', () => { + const view = mount( + ); @@ -145,7 +169,7 @@ describe('checkbox select', () => { test('renders closed successfully - old classes', () => { const view = mount( - {checkboxSelectOptions} ); @@ -154,7 +178,7 @@ describe('checkbox select', () => { test('renders expanded successfully', () => { const view = mount( - {selectOptions} ); @@ -163,7 +187,7 @@ describe('checkbox select', () => { test('renders expanded successfully - old classes', () => { const view = mount( - {checkboxSelectOptions} ); @@ -173,6 +197,7 @@ describe('checkbox select', () => { test('renders expanded with filtering successfully', () => { const view = mount( + ); @@ -197,7 +222,7 @@ describe('checkbox select', () => { test('renders checkbox select groups successfully', () => { const view = mount( - {selectOptions} {selectOptions} @@ -207,7 +232,7 @@ describe('checkbox select', () => { test('renders checkbox select groups successfully - old classes', () => { const view = mount( - {checkboxSelectOptions} {checkboxSelectOptions} @@ -219,7 +244,7 @@ describe('checkbox select', () => { describe('typeahead select', () => { test('renders closed successfully', () => { const view = mount( - {selectOptions} ); @@ -228,7 +253,7 @@ describe('typeahead select', () => { test('renders expanded successfully', () => { const view = mount( - {selectOptions} ); @@ -237,7 +262,7 @@ describe('typeahead select', () => { test('renders selected successfully', () => { const view = mount( - {selectOptions} ); @@ -248,6 +273,7 @@ describe('typeahead select', () => { const mockEvent = { target: { value: 'test' } } as React.ChangeEvent; const view = mount( + ); @@ -280,7 +306,7 @@ describe('typeahead select', () => { describe('typeahead multi select', () => { test('renders closed successfully', () => { const view = mount( - {selectOptions} ); @@ -289,7 +315,7 @@ describe('typeahead multi select', () => { test('renders expanded successfully', () => { const view = mount( - {selectOptions} ); @@ -299,6 +325,7 @@ describe('typeahead multi select', () => { test('renders selected successfully', () => { const view = mount( { const mockToggle = jest.fn(); const mockSelect = jest.fn(); const view = mount( - {selectOptions} ); @@ -352,7 +380,7 @@ describe('API', () => { const myMock = jest.fn(); global.console = { ...global.console, error: myMock }; mount( - {selectOptions} ); @@ -364,7 +392,7 @@ describe('toggle icon', () => { const ToggleIcon =
Icon
; test('select single', () => { const view = mount( - {selectOptions} ); @@ -373,7 +401,7 @@ describe('toggle icon', () => { test('select checkbox', () => { const view = mount( - {selectOptions} ); @@ -382,7 +410,7 @@ describe('toggle icon', () => { test('typeahead select', () => { const view = mount( - {selectOptions} ); @@ -391,7 +419,7 @@ describe('toggle icon', () => { test('typeahead multi select', () => { const view = mount( - {selectOptions} ); @@ -401,11 +429,11 @@ describe('toggle icon', () => { describe('select with custom content', () => { test('renders closed successfully', () => { - const view = mount(); expect(view).toMatchSnapshot(); }); test('renders expanded successfully', () => { - const view = mount(); expect(view).toMatchSnapshot(); }); }); diff --git a/packages/react-core/src/components/Select/__tests__/__snapshots__/Select.test.tsx.snap b/packages/react-core/src/components/Select/__tests__/__snapshots__/Select.test.tsx.snap index fd86cfbaeb2..5659684380a 100644 --- a/packages/react-core/src/components/Select/__tests__/__snapshots__/Select.test.tsx.snap +++ b/packages/react-core/src/components/Select/__tests__/__snapshots__/Select.test.tsx.snap @@ -6,6 +6,7 @@ exports[`checkbox select renders checkbox select groups successfully - old class isGrouped={true} onSelect={[MockFunction]} onToggle={[MockFunction]} + toggleId="checkbox-select-expanded-groups-old" variant="checkbox" > @@ -157,11 +159,11 @@ exports[`checkbox select renders checkbox select groups successfully - old class >