diff --git a/__tests__/__snapshots__/storyshots.test.js.snap b/__tests__/__snapshots__/storyshots.test.js.snap index 91ef7d9a3..a4b199350 100644 --- a/__tests__/__snapshots__/storyshots.test.js.snap +++ b/__tests__/__snapshots__/storyshots.test.js.snap @@ -6060,6 +6060,46 @@ exports[`Storyshots Components/DropdownMenu Basic 1`] = ` `; +exports[`Storyshots Components/DropdownMenu With Custom Toggle 1`] = ` +
+ +
+`; + exports[`Storyshots Components/DropdownMenu With Separators 1`] = `
{ +describe('DropdownMenu Component', () => { + test('Should render custom toggle', () => { + const textToTest = 'custom toggle' + + const { queryByText } = render( + {textToTest} }} + /> + ) + + expect(queryByText(textToTest)).toBeInTheDocument() + }) + + test('Should render custom toggle styles', () => { + const { queryByText } = render( + + ) + + expect(queryByText('None').classList.contains('customClass')).toBeTruthy() + }) + test('Should render divider when an item is null', () => { const { container, queryByRole } = render( diff --git a/components/DropdownMenu.tsx b/components/DropdownMenu.tsx index 85a9dd0fa..828aed5d3 100644 --- a/components/DropdownMenu.tsx +++ b/components/DropdownMenu.tsx @@ -19,6 +19,10 @@ type DropDownMenuProps = { //changes the underlying component CSS base class name //https://react-bootstrap.github.io/components/dropdowns/#api bsPrefix?: string + customToggle?: { + Component?: () => JSX.Element + style?: string + } } const ChevronRight = () => @@ -26,6 +30,7 @@ const ChevronRight = () => export const DropdownMenu: React.FC = ({ items, title, + customToggle, bsPrefix = '' }) => { const [activeItem, setActiveItem] = useState({ title }) @@ -33,12 +38,18 @@ export const DropdownMenu: React.FC = ({ return ( - {activeItem.title || 'None'} - + {customToggle?.Component ? ( + + ) : ( + <> + {activeItem.title || 'None'} + + + )} diff --git a/components/__snapshots__/DropdownMenu.test.js.snap b/components/__snapshots__/DropdownMenu.test.js.snap index 4d79c00c0..f05c845ef 100644 --- a/components/__snapshots__/DropdownMenu.test.js.snap +++ b/components/__snapshots__/DropdownMenu.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`MdInput Component Should change value of testBtnOnClick upon click 1`] = ` +exports[`DropdownMenu Component Should change value of testBtnOnClick upon click 1`] = `