Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,10 @@ export namespace Components {
* Where to align the fab horizontally in the viewport.
*/
"horizontal"?: 'start' | 'end' | 'center';
/**
* Opens/Closes the FAB list container.
*/
"toggle": () => Promise<void>;
/**
* Where to align the fab vertically in the viewport.
*/
Expand Down
16 changes: 16 additions & 0 deletions core/src/components/fab-button/fab-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { createColorClasses, hostContext, openURL } from '../../utils/theme';
shadow: true,
})
export class FabButton implements ComponentInterface, AnchorInterface, ButtonInterface {
private fab: HTMLIonFabElement | null = null;

@Element() el!: HTMLElement;

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

connectedCallback() {
this.fab = this.el.closest('ion-fab');
}

private onFocus = () => {
this.ionFocus.emit();
};
Expand All @@ -127,6 +133,15 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt
this.ionBlur.emit();
};

private onClick = () => {
const { fab } = this;
if (!fab) {
return;
}

fab.toggle();
};

render() {
const { el, disabled, color, href, activated, show, translucent, size } = this;
const inList = hostContext('ion-fab-list', el);
Expand All @@ -144,6 +159,7 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt

return (
<Host
onClick={this.onClick}
aria-disabled={disabled ? 'true' : null}
class={createColorClasses(color, {
[mode]: true,
Expand Down
15 changes: 8 additions & 7 deletions core/src/components/fab/fab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,23 @@ export class Fab implements ComponentInterface {
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 getButton = this.getFab();
const isButtonDisabled = getButton?.disabled;

if (hasList && !isButtonDisabled) {
if (hasList) {
this.activated = !this.activated;
}
};
}

render() {
const { horizontal, vertical, edge } = this;
const mode = getIonMode(this);
return (
<Host
onClick={this.onClick}
class={{
[mode]: true,
[`fab-horizontal-${horizontal}`]: horizontal !== undefined,
Expand Down