Skip to content

Commit

Permalink
fix: keyboard navigation when using position fixed (#5792) (#5794)
Browse files Browse the repository at this point in the history
Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
  • Loading branch information
vaadin-bot and sissbruecker committed Apr 27, 2023
1 parent cc7ceef commit a1a413d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/component-base/src/focus-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ export function isElementHidden(element) {
// `offsetParent` is `null` when the element itself
// or one of its ancestors is hidden with `display: none`.
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent
if (element.offsetParent === null) {
// However `offsetParent` is also null when the element is using fixed
// positioning, so additionally check if the element takes up layout space.
if (element.offsetParent === null && element.clientWidth === 0 && element.clientHeight === 0) {
return true;
}

Expand Down
7 changes: 6 additions & 1 deletion packages/component-base/test/focus-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('focus-utils', () => {
beforeEach(() => {
element = fixtureSync(`
<div class="parent">
<div class="child"></div>
<div class="child">foo</div>
</div>
`);
});
Expand Down Expand Up @@ -43,6 +43,11 @@ describe('focus-utils', () => {
it('should return false for visible elements', () => {
expect(isElementHidden(element)).to.be.false;
});

it('should return false when using fixed positioning', () => {
element.style.position = 'fixed';
expect(isElementHidden(element)).to.be.false;
});
});

describe('isElementFocusable', () => {
Expand Down

0 comments on commit a1a413d

Please sign in to comment.