Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dropdown toggle missing .show class when active #6508

Merged
merged 1 commit into from Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/DropdownToggle.tsx
@@ -1,15 +1,14 @@
import useMergedRefs from '@restart/hooks/useMergedRefs';
import DropdownContext from '@restart/ui/DropdownContext';
import { useDropdownToggle } from '@restart/ui/DropdownToggle';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import * as React from 'react';
import { useContext } from 'react';
import { useDropdownToggle } from '@restart/ui/DropdownToggle';
import DropdownContext from '@restart/ui/DropdownContext';
import useMergedRefs from '@restart/hooks/useMergedRefs';
import Button, { ButtonProps, CommonButtonProps } from './Button';
import InputGroupContext from './InputGroupContext';
import { BsPrefixRefForwardingComponent } from './helpers';
import { useBootstrapPrefix } from './ThemeProvider';
import useWrappedRefWithWarning from './useWrappedRefWithWarning';
import { BsPrefixRefForwardingComponent } from './helpers';

export interface DropdownToggleProps extends Omit<ButtonProps, 'as'> {
as?: React.ElementType;
Expand Down Expand Up @@ -64,7 +63,6 @@ const DropdownToggle: DropdownToggleComponent = React.forwardRef(
) => {
const prefix = useBootstrapPrefix(bsPrefix, 'dropdown-toggle');
const dropdownContext = useContext(DropdownContext);
const isInputGroup = useContext(InputGroupContext);

if (childBsPrefix !== undefined) {
(props as any).bsPrefix = childBsPrefix;
Expand All @@ -85,7 +83,7 @@ const DropdownToggle: DropdownToggleComponent = React.forwardRef(
className,
prefix,
split && `${prefix}-split`,
!!isInputGroup && dropdownContext?.show && 'show',
dropdownContext?.show && 'show',
)}
{...toggleProps}
{...props}
Expand Down
7 changes: 7 additions & 0 deletions test/DropdownSpec.tsx
Expand Up @@ -230,6 +230,13 @@ describe('<Dropdown>', () => {
onToggleSpy.getCall(0).args[0].should.equal(true);
onToggleSpy.getCall(0).args[1].source.should.equal('keydown');
});

it('Should render .show on the dropdown toggle when outside an InputGroup', () => {
const { getByText } = render(
<Dropdown show>{dropdownChildren}</Dropdown>,
);
getByText('Child Title').classList.contains('show').should.be.true;
});
});

it('should use each components bsPrefix', () => {
Expand Down