Skip to content

Commit

Permalink
Merge pull request #2774 from IntellyCode/master
Browse files Browse the repository at this point in the history
Fixed Dropdown with inNavbar bug
  • Loading branch information
davidacevedo committed Jan 19, 2024
2 parents 85cd68b + f2362aa commit 5a95269
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
10 changes: 9 additions & 1 deletion src/Dropdown.js
Expand Up @@ -98,12 +98,19 @@ class Dropdown extends React.Component {
const menu = this.getMenu();
const toggle = this.getToggle();

// Add a conditional check to avoid using toggle
//if there is no toggle component in the dropdown

Check failure on line 102 in src/Dropdown.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Expected exception block, space or tab after '//' in comment

Check failure on line 102 in src/Dropdown.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected exception block, space or tab after '//' in comment

Check failure on line 102 in src/Dropdown.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected exception block, space or tab after '//' in comment
if (!toggle) {
return;
}

const targetIsToggle = toggle.contains(e.target);

const clickIsInMenu = menu && menu.contains(e.target) && menu !== e.target;

let clickIsInInput = false;
if (container) {
// this is only for InputGroup with type dropdown
// This is only for InputGroup with type dropdown
clickIsInInput =
container.classList.contains('input-group') &&
container.classList.contains('dropdown') &&
Expand All @@ -120,6 +127,7 @@ class Dropdown extends React.Component {
this.toggle(e);
}


handleKeyDown(e) {
const isTargetMenuItem =
e.target.getAttribute('role') === 'menuitem' ||
Expand Down
45 changes: 23 additions & 22 deletions src/DropdownToggle.js
Expand Up @@ -99,43 +99,44 @@ class DropdownToggle extends React.Component {
Tag = tag;
}

if (this.context.inNavbar) {
//extracted the rendering of the Tag component

Check failure on line 102 in src/DropdownToggle.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Expected exception block, space or tab after '//' in comment

Check failure on line 102 in src/DropdownToggle.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected exception block, space or tab after '//' in comment

Check failure on line 102 in src/DropdownToggle.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected exception block, space or tab after '//' in comment
const returnFunction = ({ ref }) => {
const handleRef = (tagRef) => {
ref(tagRef);
const { onToggleRef } = this.context;
if (onToggleRef) onToggleRef(tagRef);
};

return (
<Tag
{...props}
{...{ [typeof Tag === 'string' ? 'ref' : 'innerRef']: handleRef }}
className={classes}
onClick={this.onClick}
ref={this.context.onToggleRef}
aria-expanded={this.context.isOpen}
aria-haspopup={this.getRole()}
children={children}
/>
);
}

//No Reference component if the component is in Navbar

Check failure on line 123 in src/DropdownToggle.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Expected exception block, space or tab after '//' in comment

Check failure on line 123 in src/DropdownToggle.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected exception block, space or tab after '//' in comment

Check failure on line 123 in src/DropdownToggle.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected exception block, space or tab after '//' in comment
if (this.context.inNavbar) {
return (
<>
{returnFunction({ ref: this.context.onToggleRef })}
</>
);
}

//Normal rendering if component not in NavBar

Check failure on line 132 in src/DropdownToggle.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Expected exception block, space or tab after '//' in comment

Check failure on line 132 in src/DropdownToggle.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected exception block, space or tab after '//' in comment

Check failure on line 132 in src/DropdownToggle.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected exception block, space or tab after '//' in comment
return (
<Reference innerRef={innerRef}>
{({ ref }) => {
const handleRef = (tagRef) => {
ref(tagRef);
const { onToggleRef } = this.context;
if (onToggleRef) onToggleRef(tagRef);
};

return (
<Tag
{...props}
{...{ [typeof Tag === 'string' ? 'ref' : 'innerRef']: handleRef }}
className={classes}
onClick={this.onClick}
aria-expanded={this.context.isOpen}
aria-haspopup={this.getRole()}
children={children}
/>
);
}}

<Reference innerRef={innerRef} >
{returnFunction}
</Reference>
);

}
}

Expand Down

0 comments on commit 5a95269

Please sign in to comment.