Skip to content

Commit efdaf90

Browse files
authored
fix(fab-button): improve ripple effect behavior on click (#25413)
resolves #21772
1 parent 72580a2 commit efdaf90

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

core/src/components.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,10 @@ export namespace Components {
847847
* Where to align the fab horizontally in the viewport.
848848
*/
849849
"horizontal"?: 'start' | 'end' | 'center';
850+
/**
851+
* Opens/Closes the FAB list container.
852+
*/
853+
"toggle": () => Promise<void>;
850854
/**
851855
* Where to align the fab vertically in the viewport.
852856
*/

core/src/components/fab-button/fab-button.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import { createColorClasses, hostContext, openURL } from '../../utils/theme';
2222
shadow: true,
2323
})
2424
export class FabButton implements ComponentInterface, AnchorInterface, ButtonInterface {
25+
private fab: HTMLIonFabElement | null = null;
26+
2527
@Element() el!: HTMLElement;
2628

2729
/**
@@ -119,6 +121,10 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt
119121
*/
120122
@Event() ionBlur!: EventEmitter<void>;
121123

124+
connectedCallback() {
125+
this.fab = this.el.closest('ion-fab');
126+
}
127+
122128
private onFocus = () => {
123129
this.ionFocus.emit();
124130
};
@@ -127,6 +133,15 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt
127133
this.ionBlur.emit();
128134
};
129135

136+
private onClick = () => {
137+
const { fab } = this;
138+
if (!fab) {
139+
return;
140+
}
141+
142+
fab.toggle();
143+
};
144+
130145
render() {
131146
const { el, disabled, color, href, activated, show, translucent, size } = this;
132147
const inList = hostContext('ion-fab-list', el);
@@ -144,6 +159,7 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt
144159

145160
return (
146161
<Host
162+
onClick={this.onClick}
147163
aria-disabled={disabled ? 'true' : null}
148164
class={createColorClasses(color, {
149165
[mode]: true,

core/src/components/fab/fab.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,23 @@ export class Fab implements ComponentInterface {
6262
return this.el.querySelector('ion-fab-button');
6363
}
6464

65-
private onClick = () => {
65+
/**
66+
* Opens/Closes the FAB list container.
67+
* @internal
68+
*/
69+
@Method()
70+
async toggle() {
6671
const hasList = !!this.el.querySelector('ion-fab-list');
67-
const getButton = this.getFab();
68-
const isButtonDisabled = getButton?.disabled;
69-
70-
if (hasList && !isButtonDisabled) {
72+
if (hasList) {
7173
this.activated = !this.activated;
7274
}
73-
};
75+
}
7476

7577
render() {
7678
const { horizontal, vertical, edge } = this;
7779
const mode = getIonMode(this);
7880
return (
7981
<Host
80-
onClick={this.onClick}
8182
class={{
8283
[mode]: true,
8384
[`fab-horizontal-${horizontal}`]: horizontal !== undefined,

0 commit comments

Comments
 (0)