Skip to content

Commit

Permalink
fix(AccordionToggle): default button type=button (#5076)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Mar 27, 2020
1 parent e87744e commit 59468d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/AccordionToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function useAccordionToggle(eventKey, onClick) {
const onSelect = useContext(SelectableContext);

return (e) => {
/*
/*
Compare the event key in context with the given event key.
If they are the same, then collapse the component.
*/
Expand All @@ -50,6 +50,10 @@ const AccordionToggle = React.forwardRef(
) => {
const accordionOnClick = useAccordionToggle(eventKey, onClick);

if (Component === 'button') {
props.type = 'button';
}

return (
<Component ref={ref} onClick={accordionOnClick} {...props}>
{children}
Expand Down
4 changes: 3 additions & 1 deletion test/AccordionToggleSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import AccordionToggle from '../src/AccordionToggle';

describe('<AccordionToggle>', () => {
it('Should have button as default component', () => {
mount(<AccordionToggle eventKey="" />).assertSingle('button');
mount(<AccordionToggle eventKey="" />).assertSingle(
'button[type="button"]',
);
});
});

0 comments on commit 59468d7

Please sign in to comment.