-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
fix(material/tabs): prevent default keyboard actions on disabled links #27274
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ import {MatInkBar, MatInkBarItem, mixinInkBarItem} from '../ink-bar'; | |
import {BooleanInput, coerceBooleanProperty, NumberInput} from '@angular/cdk/coercion'; | ||
import {BehaviorSubject, Subject} from 'rxjs'; | ||
import {startWith, takeUntil} from 'rxjs/operators'; | ||
import {SPACE} from '@angular/cdk/keycodes'; | ||
import {ENTER, SPACE} from '@angular/cdk/keycodes'; | ||
import {MAT_TABS_CONFIG, MatTabsConfig} from '../tab-config'; | ||
import {MatPaginatedTabHeader, MatPaginatedTabHeaderItem} from '../paginated-tab-header'; | ||
|
||
|
@@ -261,7 +261,9 @@ export class _MatTabLinkBase | |
} | ||
|
||
_handleKeydown(event: KeyboardEvent) { | ||
if (this._tabNavBar.tabPanel && event.keyCode === SPACE) { | ||
if (this.disabled && (event.keyCode === SPACE || event.keyCode === ENTER)) { | ||
event.preventDefault(); | ||
} else if (this._tabNavBar.tabPanel && event.keyCode === SPACE) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can switch to focused tab when we press Enter key too? Shouldn't it be like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The enter condition is in there since some browsers do clicks both on enter and space, IIRC. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it, ig. I tried to navigate while tab being focused & pressing enter but it didn't navigate me, although it worked when I used spacebar only. Chrome 113.0.5672.92, Firefox 113.0.1 nor Chrome 104.0.5112.101. |
||
this.elementRef.nativeElement.click(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functionality was covered in another test so I deleted this one.