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

JENKINS-47022 - Fix for dropdown losing focus on selection, back port to 1.4 #1660

Merged
merged 2 commits into from Feb 16, 2018
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
2 changes: 1 addition & 1 deletion jenkins-design-language/package.json
@@ -1,7 +1,7 @@
{
"name": "@jenkins-cd/design-language",
"jdlName": "jenkins-design-language",
"version": "0.0.158",
"version": "0.0.160",
"description": "Styles, assets, and React classes for Jenkins Design Language",
"main": "dist/js/components/index.js",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions jenkins-design-language/src/js/components/forms/Dropdown.jsx
Expand Up @@ -265,6 +265,11 @@ export class Dropdown extends React.Component {
if (this.props.onChange) {
this.props.onChange(option, index);
}

//restore the focus on the button element
if (this.buttonRef && this.buttonRef.focus) {
this.buttonRef.focus();
}
}

_optionToLabel(option) {
Expand Down
16 changes: 16 additions & 0 deletions jenkins-design-language/test/js/components/Dropdown-spec.jsx
Expand Up @@ -56,4 +56,20 @@ describe("Dropdown", () => {
assert.equal(drop.find('ul.Dropdown-menu li').length, options.length); // dropdown options same length then our array?
assert.equal(drop.find('#unit').length, 1); // only on footer?
});
it('dropDown should still have focus after option selection', () => {
const wrapper = mount(<Dropdown { ...{
options,
}}
/>);
assert.ok(wrapper);
const drop = wrapper.find('Dropdown');
// click the dropDown button
drop.find('button').simulate('click');
// click on the 1st option
drop.find("li a").first().simulate('click');
//get focused element
const focusedElement = document.activeElement;
//verify that the focused element is the dropdown button
assert.equal(focusedElement, drop.find('button').get(0));
});
});