Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ ion-fab-button,part,native

ion-fab-list,shadow
ion-fab-list,prop,activated,boolean,false,false,false
ion-fab-list,prop,animated,boolean | undefined,undefined,false,false
ion-fab-list,prop,side,"bottom" | "end" | "start" | "top",'bottom',false,false

ion-footer,none
Expand Down
13 changes: 11 additions & 2 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ export namespace Components {
*/
"activated": boolean;
/**
* If `true`, the fab button will animate between states, such as swapping its content for the close icon.
* If `true`, the fab button will animate between states, such as swapping its content for the close icon. As the main button of an `ion-fab`, it also sets whether the `ion-fab-list` buttons show one at a time, unless the list sets its own `animated`.
* @default true
*/
"animated": boolean;
Expand Down Expand Up @@ -1207,6 +1207,10 @@ export namespace Components {
* @default false
*/
"activated": boolean;
/**
* If `true`, the fab buttons in the list will show one at a time when the list opens. If not set, it follows the main fab button's `animated`.
*/
"animated"?: boolean;
/**
* The side the fab list will show on relative to the main fab button.
* @default 'bottom'
Expand Down Expand Up @@ -6279,7 +6283,7 @@ declare namespace LocalJSX {
*/
"activated"?: boolean;
/**
* If `true`, the fab button will animate between states, such as swapping its content for the close icon.
* If `true`, the fab button will animate between states, such as swapping its content for the close icon. As the main button of an `ion-fab`, it also sets whether the `ion-fab-list` buttons show one at a time, unless the list sets its own `animated`.
* @default true
*/
"animated"?: boolean;
Expand Down Expand Up @@ -6364,6 +6368,10 @@ declare namespace LocalJSX {
* @default false
*/
"activated"?: boolean;
/**
* If `true`, the fab buttons in the list will show one at a time when the list opens. If not set, it follows the main fab button's `animated`.
*/
"animated"?: boolean;
/**
* The side the fab list will show on relative to the main fab button.
* @default 'bottom'
Expand Down Expand Up @@ -9207,6 +9215,7 @@ declare namespace LocalJSX {
interface IonFabListAttributes {
"activated": boolean;
"side": 'start' | 'end' | 'top' | 'bottom';
"animated": boolean;
}
interface IonFooterAttributes {
"collapse": 'fade';
Expand Down
4 changes: 3 additions & 1 deletion core/src/components/fab-button/fab-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt

/**
* If `true`, the fab button will animate between states, such as
* swapping its content for the close icon.
* swapping its content for the close icon. As the main button of an
* `ion-fab`, it also sets whether the `ion-fab-list` buttons show one
* at a time, unless the list sets its own `animated`.
*/
@Prop() animated = true;

Expand Down
23 changes: 21 additions & 2 deletions core/src/components/fab-list/fab-list.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { ComponentInterface } from '@stencil/core';
import { Component, Element, Host, Prop, Watch, h } from '@stencil/core';
import { win } from '@utils/browser';

import { config } from '../../global/config';
import { getIonMode } from '../../global/ionic-global';

@Component({
Expand All @@ -24,8 +26,7 @@ export class FabList implements ComponentInterface {

const fabs = Array.from(this.el.querySelectorAll('ion-fab-button'));

// if showing the fabs add a timeout, else show immediately
const timeout = activated ? 30 : 0;
const timeout = activated && this.shouldAnimate() ? 30 : 0;
fabs.forEach((fab, i) => {
this.activateTimeouts.push(setTimeout(() => (fab.show = activated), i * timeout));
});
Expand All @@ -36,11 +37,29 @@ export class FabList implements ComponentInterface {
*/
@Prop() side: 'start' | 'end' | 'top' | 'bottom' = 'bottom';

/**
* If `true`, the fab buttons in the list will show one at a time
* when the list opens. If not set, it follows the main fab button's
* `animated`.
*/
Comment on lines +41 to +44

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs table will show no default for this prop, since it has none. The JSDoc also doesn't say what an unset list does outside an ion-fab, so a reader can't tell that it still shows its buttons one at a time:

Suggested change
* If `true`, the fab buttons in the list will show one at a time
* when the list opens. If not set, it follows the main fab button's
* `animated`.
*/
* If `true`, the fab buttons in the list will show one at a time
* when the list opens. If not set, it follows the `animated`
* property of the main fab button in its `ion-fab`, or `true`
* when the list is not in an `ion-fab`.

@Prop() animated?: boolean;

disconnectedCallback() {
this.activateTimeouts.forEach(clearTimeout);
this.activateTimeouts = [];
}

private shouldAnimate() {
const fabButton = this.el.closest('ion-fab')?.querySelector<HTMLIonFabButtonElement>(':scope > ion-fab-button');
const animated = this.animated ?? fabButton?.animated ?? true;

if (!animated || !config.getBoolean('animated', true)) {
return false;
Comment thread
brandyscarney marked this conversation as resolved.
Resolved
}

return !win?.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
}

render() {
const mode = getIonMode(this);
return (
Expand Down
92 changes: 92 additions & 0 deletions core/src/components/fab-list/test/animation/fab-list.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { expect } from '@playwright/test';
import type { Page } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';

/**
* Returns each list button's `show` right after opening, when a
* staggered list has only shown its first button.
*/
const activateAndGetShownButtons = (page: Page, selector: 'ion-fab' | 'ion-fab-list' = 'ion-fab') =>
page.locator(selector).evaluate(async (el: HTMLIonFabElement | HTMLIonFabListElement) => {
el.activated = true;
await new Promise((resolve) => setTimeout(resolve, 0));
return Array.from(el.querySelectorAll('ion-fab-list ion-fab-button')).map(
(button) => (button as HTMLIonFabButtonElement).show
);
});

const listButtons = `
<ion-fab-button><ion-icon name="logo-facebook"></ion-icon></ion-fab-button>
<ion-fab-button><ion-icon name="logo-twitter"></ion-icon></ion-fab-button>
<ion-fab-button><ion-icon name="logo-vimeo"></ion-icon></ion-fab-button>
`;

const fabMarkup = ({ fabButtonAttrs = '', fabListAttrs = '' } = {}) => `
<ion-fab>
<ion-fab-button ${fabButtonAttrs}>
<ion-icon name="add"></ion-icon>
</ion-fab-button>
<ion-fab-list ${fabListAttrs}>${listButtons}</ion-fab-list>
</ion-fab>
`;

/**
* This behavior does not vary across modes/directions.
*/
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
test.describe(title('fab-list: animation'), () => {
test('should show the list buttons one at a time by default', async ({ page }) => {
await page.setContent(fabMarkup(), config);

expect(await activateAndGetShownButtons(page)).toEqual([true, false, false]);
await expect(page.locator('ion-fab-list ion-fab-button').last()).toHaveClass(/fab-button-show/);
});

test('should show the list buttons one at a time by default outside of a fab', async ({ page }) => {
await page.setContent(`<ion-fab-list>${listButtons}</ion-fab-list>`, config);

expect(await activateAndGetShownButtons(page, 'ion-fab-list')).toEqual([true, false, false]);
});

test('should show all list buttons at once when animated is false outside of a fab', async ({ page }) => {
await page.setContent(`<ion-fab-list animated="false">${listButtons}</ion-fab-list>`, config);

expect(await activateAndGetShownButtons(page, 'ion-fab-list')).toEqual([true, true, true]);
});

test('should show all list buttons at once when the animated config is false', async ({ page }) => {
await page.setContent(`<script>window.Ionic.config.animated = false;</script>${fabMarkup()}`, config);

expect(await activateAndGetShownButtons(page)).toEqual([true, true, true]);
});

test('should show all list buttons at once when the user prefers reduced motion', async ({ page }) => {
await page.emulateMedia({ reducedMotion: 'reduce' });
await page.setContent(fabMarkup(), config);

expect(await activateAndGetShownButtons(page)).toEqual([true, true, true]);
});

test('should show all list buttons at once when the main fab button is not animated', async ({ page }) => {
await page.setContent(fabMarkup({ fabButtonAttrs: 'animated="false"' }), config);

expect(await activateAndGetShownButtons(page)).toEqual([true, true, true]);
});

test('should show all list buttons at once when the list is not animated under an animated main fab button', async ({
page,
}) => {
await page.setContent(fabMarkup({ fabListAttrs: 'animated="false"' }), config);

expect(await activateAndGetShownButtons(page)).toEqual([true, true, true]);
});

test('should show the list buttons one at a time when the list is animated under a main fab button that is not', async ({
page,
}) => {
await page.setContent(fabMarkup({ fabButtonAttrs: 'animated="false"', fabListAttrs: 'animated="true"' }), config);

expect(await activateAndGetShownButtons(page)).toEqual([true, false, false]);
});
});
});
4 changes: 2 additions & 2 deletions packages/angular/src/lazy/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,14 +831,14 @@ export declare interface IonFabButton extends Components.IonFabButton {


@ProxyCmp({
inputs: ['activated', 'side']
inputs: ['activated', 'animated', 'side']
})
@Component({
selector: 'ion-fab-list',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['activated', 'side'],
inputs: ['activated', 'animated', 'side'],
standalone: false
})
export class IonFabList {
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/standalone/directives/ion-fab-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { defineCustomElement as defineIonFabList } from '@ionic/core/components/

@ProxyCmp({
defineCustomElementFn: defineIonFabList,
inputs: ['activated', 'side']
inputs: ['activated', 'animated', 'side']
})
@Component({
selector: 'ion-fab-list',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['activated', 'side'],
inputs: ['activated', 'animated', 'side'],
})
export class IonFabList {
protected el: HTMLIonFabListElement;
Expand Down
3 changes: 2 additions & 1 deletion packages/vue/src/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ export const IonFabButton: StencilVueComponent<JSX.IonFabButton> = /*@__PURE__*/

export const IonFabList: StencilVueComponent<JSX.IonFabList> = /*@__PURE__*/ defineContainer<JSX.IonFabList>('ion-fab-list', defineIonFabList, [
'activated',
'side'
'side',
'animated'
]);


Expand Down
Loading