mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 03:00:58 +08:00
fix(fab-button): improve ripple effect behavior on click (#25413)
resolves #21772
This commit is contained in:
4
core/src/components.d.ts
vendored
4
core/src/components.d.ts
vendored
@ -847,6 +847,10 @@ export namespace Components {
|
|||||||
* Where to align the fab horizontally in the viewport.
|
* Where to align the fab horizontally in the viewport.
|
||||||
*/
|
*/
|
||||||
"horizontal"?: 'start' | 'end' | 'center';
|
"horizontal"?: 'start' | 'end' | 'center';
|
||||||
|
/**
|
||||||
|
* Opens/Closes the FAB list container.
|
||||||
|
*/
|
||||||
|
"toggle": () => Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Where to align the fab vertically in the viewport.
|
* Where to align the fab vertically in the viewport.
|
||||||
*/
|
*/
|
||||||
|
@ -22,6 +22,8 @@ import { createColorClasses, hostContext, openURL } from '../../utils/theme';
|
|||||||
shadow: true,
|
shadow: true,
|
||||||
})
|
})
|
||||||
export class FabButton implements ComponentInterface, AnchorInterface, ButtonInterface {
|
export class FabButton implements ComponentInterface, AnchorInterface, ButtonInterface {
|
||||||
|
private fab: HTMLIonFabElement | null = null;
|
||||||
|
|
||||||
@Element() el!: HTMLElement;
|
@Element() el!: HTMLElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,6 +121,10 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt
|
|||||||
*/
|
*/
|
||||||
@Event() ionBlur!: EventEmitter<void>;
|
@Event() ionBlur!: EventEmitter<void>;
|
||||||
|
|
||||||
|
connectedCallback() {
|
||||||
|
this.fab = this.el.closest('ion-fab');
|
||||||
|
}
|
||||||
|
|
||||||
private onFocus = () => {
|
private onFocus = () => {
|
||||||
this.ionFocus.emit();
|
this.ionFocus.emit();
|
||||||
};
|
};
|
||||||
@ -127,6 +133,15 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt
|
|||||||
this.ionBlur.emit();
|
this.ionBlur.emit();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private onClick = () => {
|
||||||
|
const { fab } = this;
|
||||||
|
if (!fab) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fab.toggle();
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { el, disabled, color, href, activated, show, translucent, size } = this;
|
const { el, disabled, color, href, activated, show, translucent, size } = this;
|
||||||
const inList = hostContext('ion-fab-list', el);
|
const inList = hostContext('ion-fab-list', el);
|
||||||
@ -144,6 +159,7 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Host
|
<Host
|
||||||
|
onClick={this.onClick}
|
||||||
aria-disabled={disabled ? 'true' : null}
|
aria-disabled={disabled ? 'true' : null}
|
||||||
class={createColorClasses(color, {
|
class={createColorClasses(color, {
|
||||||
[mode]: true,
|
[mode]: true,
|
||||||
|
@ -62,22 +62,23 @@ export class Fab implements ComponentInterface {
|
|||||||
return this.el.querySelector('ion-fab-button');
|
return this.el.querySelector('ion-fab-button');
|
||||||
}
|
}
|
||||||
|
|
||||||
private onClick = () => {
|
/**
|
||||||
|
* Opens/Closes the FAB list container.
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
@Method()
|
||||||
|
async toggle() {
|
||||||
const hasList = !!this.el.querySelector('ion-fab-list');
|
const hasList = !!this.el.querySelector('ion-fab-list');
|
||||||
const getButton = this.getFab();
|
if (hasList) {
|
||||||
const isButtonDisabled = getButton?.disabled;
|
|
||||||
|
|
||||||
if (hasList && !isButtonDisabled) {
|
|
||||||
this.activated = !this.activated;
|
this.activated = !this.activated;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { horizontal, vertical, edge } = this;
|
const { horizontal, vertical, edge } = this;
|
||||||
const mode = getIonMode(this);
|
const mode = getIonMode(this);
|
||||||
return (
|
return (
|
||||||
<Host
|
<Host
|
||||||
onClick={this.onClick}
|
|
||||||
class={{
|
class={{
|
||||||
[mode]: true,
|
[mode]: true,
|
||||||
[`fab-horizontal-${horizontal}`]: horizontal !== undefined,
|
[`fab-horizontal-${horizontal}`]: horizontal !== undefined,
|
||||||
|
Reference in New Issue
Block a user