Skip to content

Commit

Permalink
Changed .focus() call to also support SVG elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed May 4, 2020
1 parent 21f05b3 commit 9fee67b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -865,24 +865,6 @@ No matching component was found for:
});

describe('focusWithin', () => {
beforeEach(() => {
// JSdom does not do actual layout and so doesn't return meaningful values here.
// For the purposes of our tests though, we need somewhat meaningful values here,
// else the DOM host config will assume elements are not visible.
Object.defineProperties(HTMLElement.prototype, {
offsetWidth: {
get: function() {
return parseInt(this.style.width, 10) || 0;
},
},
offsetHeight: {
get: function() {
return parseInt(this.style.height, 10) || 0;
},
},
});
});

it('should return false if the specified component path has no matches', () => {
function Example() {
return <Child />;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ export function setFocusIfFocusable(node: Instance): boolean {
const element = ((node: any): HTMLElement);
try {
element.addEventListener('focus', handleFocus);
element.focus();
(element.focus || HTMLElement.prototype.focus).call(element);
} finally {
element.removeEventListener('focus', handleFocus);
}
Expand Down

0 comments on commit 9fee67b

Please sign in to comment.