mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 02:31:34 +08:00
fix(inputs): keyboard focus improvements (#16838)
fixes #16815 fixes #16872 fixes #13978 fixes #16610
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { Component, ComponentInterface, Element, Event, EventEmitter, Prop, State } from '@stencil/core';
|
||||
import { Component, ComponentInterface, Element, Event, EventEmitter, Listen, Prop } from '@stencil/core';
|
||||
|
||||
import { Color, Mode, RouterDirection } from '../../interface';
|
||||
import { hasShadowDom } from '../../utils/helpers';
|
||||
@ -20,8 +20,6 @@ export class Button implements ComponentInterface {
|
||||
|
||||
@Prop({ context: 'window' }) win!: Window;
|
||||
|
||||
@State() keyFocus = false;
|
||||
|
||||
/**
|
||||
* The color to use from your application's color palette.
|
||||
* Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`.
|
||||
@ -103,20 +101,8 @@ export class Button implements ComponentInterface {
|
||||
this.inToolbar = !!this.el.closest('ion-buttons');
|
||||
}
|
||||
|
||||
private onFocus = () => {
|
||||
this.ionFocus.emit();
|
||||
}
|
||||
|
||||
private onKeyUp = () => {
|
||||
this.keyFocus = true;
|
||||
}
|
||||
|
||||
private onBlur = () => {
|
||||
this.keyFocus = false;
|
||||
this.ionBlur.emit();
|
||||
}
|
||||
|
||||
private onClick = (ev: Event) => {
|
||||
@Listen('click')
|
||||
onClick(ev: Event) {
|
||||
if (this.type === 'button') {
|
||||
return openURL(this.win, this.href, ev, this.routerDirection);
|
||||
|
||||
@ -139,14 +125,22 @@ export class Button implements ComponentInterface {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
private onFocus = () => {
|
||||
this.ionFocus.emit();
|
||||
}
|
||||
|
||||
private onBlur = () => {
|
||||
this.ionBlur.emit();
|
||||
}
|
||||
|
||||
hostData() {
|
||||
const { buttonType, keyFocus, disabled, color, expand, shape, size, strong } = this;
|
||||
const { buttonType, disabled, color, expand, shape, size, strong } = this;
|
||||
let fill = this.fill;
|
||||
if (fill === undefined) {
|
||||
fill = this.inToolbar ? 'clear' : 'solid';
|
||||
}
|
||||
return {
|
||||
'aria-disabled': this.disabled ? 'true' : null,
|
||||
'aria-disabled': disabled ? 'true' : null,
|
||||
class: {
|
||||
...createColorClasses(color),
|
||||
[buttonType]: true,
|
||||
@ -156,9 +150,9 @@ export class Button implements ComponentInterface {
|
||||
[`${buttonType}-${fill}`]: true,
|
||||
[`${buttonType}-strong`]: strong,
|
||||
|
||||
'focused': keyFocus,
|
||||
'button-disabled': disabled,
|
||||
'ion-activatable': true,
|
||||
'ion-focusable': true,
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -175,9 +169,7 @@ export class Button implements ComponentInterface {
|
||||
class="button-native"
|
||||
disabled={this.disabled}
|
||||
onFocus={this.onFocus}
|
||||
onKeyUp={this.onKeyUp}
|
||||
onBlur={this.onBlur}
|
||||
onClick={this.onClick}
|
||||
>
|
||||
<span class="button-inner">
|
||||
<slot name="icon-only"></slot>
|
||||
|
Reference in New Issue
Block a user