By looking at, https://v5.material.angular.io/components/select/overview
There are several keyboard interactions.
- Keyboard interaction
- DOWN_ARROW: Focus next option
- UP_ARROW: Focus previous option
- ENTER or SPACE: Select focused item
I am able to stop the whole interaction, BUT what I want is:
keep the all the keyboard interactions, except the SPACE one
Is there a way to do it?
Thank you.
CodePudding user response:
If you look at the source code, you'll find that the keys are hardcoded. Therefore, you cannot easily override them.
Besides that, you probably should not override them anyways sice this would conflict with accessibility.
CodePudding user response:
Take account the Georg-un's answer
But if there a great great reason you always can "re-writte" the function.
Use a template reference variable in your select
<mat-select #select="matSelect">
...
</mat-select>
And you can use ViewChild to get the mat select and rewrite the function
@ViewChild('select', { static: true }) select: any;
ngOnInit() {
this.select._handleKeydown = (event: KeyboardEvent) => {
if (event.keyCode==SPACE)
return
if (!this.select.disabled) {
this.select.panelOpen
? this.select._handleOpenKeydown(event)
: this.select._handleClosedKeydown(event);
}
};
}
NOTE: SPACE is defined in
import { SPACE} from '@angular/cdk/keycodes';