Skip to content

Commit

Permalink
fix(material/tabs): prevent page scroll on space press (#28532)
Browse files Browse the repository at this point in the history
This appears to be a regression from #27862 where the `preventDefault` was removed both from space and enter presses. We still need it on space so that the page doesn't scroll.

Fixes #28392.

(cherry picked from commit 556bcc3)
  • Loading branch information
crisbeto committed Feb 8, 2024
1 parent 2201c73 commit f6eed51
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/material/tabs/tab-nav-bar/tab-nav-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ export class MatTabLink
if (this.disabled) {
event.preventDefault();
} else if (this._tabNavBar.tabPanel) {
// Only prevent the default action on space since it can scroll the page.
// Don't prevent enter since it can break link navigation.
if (event.keyCode === SPACE) {
event.preventDefault();
}

this.elementRef.nativeElement.click();
}
}
Expand Down

0 comments on commit f6eed51

Please sign in to comment.