Dropdown (PF4): When the first DropdownItem in the Dropdown has an onClick handler keyboard navigation does not work
See original GitHub issueAs the title says - when the first item in the DropdownItems has an onClick handler that will consume the space key down on the dropdown element, which is supposed to expand the dropdown, and the keyboard navigation will not work properly.
Reproducer is the following code:
import React from 'react';
import {
Dropdown,
DropdownToggle,
DropdownItem,
DropdownSeparator,
DropdownPosition,
DropdownDirection,
KebabToggle
} from '@patternfly/react-core';
import { ThIcon } from '@patternfly/react-icons';
class PositionRightDropdown extends React.Component {
constructor(props) {
super(props);
this.state = {
isOpen: false
};
this.onToggle = isOpen => {
this.setState({
isOpen
});
};
this.onSelect = event => {
this.setState({
isOpen: !this.state.isOpen
});
this.onFocus();
};
this.onFocus = () => {
const element = document.getElementById('toggle-id-5');
element.focus();
};
}
render() {
const { isOpen } = this.state;
const dropdownItems = [
<DropdownItem key="test" component="button" onClick={() => console.info('First link pressed')}>Link</DropdownItem>
];
return (
<Dropdown
onSelect={this.onSelect}
position={DropdownPosition.right}
toggle={<DropdownToggle onToggle={this.onToggle}>Dropdown</DropdownToggle>}
isOpen={isOpen}
dropdownItems={dropdownItems}
/>
);
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Onclick Function in Dropdown Menu not working
Everything is working except the onclick function. Can anyone point out where I'm going wrong? function show(anything) { document ...
Read more >Checkbox: onClick doesn't fire when inside a Dropdown #2121
The DropdownItem.create() factory call needs to no override the onClick handler, but wrap it. An example of this is shown in the same...
Read more >Fly-out Menus | Web Accessibility Initiative (WAI) - W3C
Use fly-out (or drop-down) menus to provide an overview of a web site's page hierarchy. It removes the need for multiple page loads...
Read more >How to avoid dropdown menu to close menu items on clicking ...
The default behavior of a dropdown menu is to close the menu list items when clicked inside. In this article, We will use...
Read more >Introduction to browser events - The Modern JavaScript Tutorial
An event is a signal that something has happened. All DOM nodes generate such signals (but events are not limited to DOM).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @KKoukiou we’ve seen this and will follow up soon with a response.
@tlabaj please reopen and as discussed in the previous cockpit/PF4 migration meeting please make sure that the bot does not close actual bugs without human approval.