Stop the ion-fab-list from automatically closing when an element is selected within it

I'm having trouble getting a form to stay visible when a fab is clicked in my Ionic 4 app. Every time I click on a fab or another component within the ion-fab-list, the ion-fab-list automatically closes. How can I prevent this from happening and keep the form open?

I've attempted using @ViewChild, but it hasn't been successful. One thing I've noticed about the @ViewChild decorator is that it requires two parameters, which seems different from other solutions I've seen.

form.component.ts

import { Component, OnInit, ViewChild } from '@angular/core';
import { NavController, IonFab } from '@ionic/angular'

@Component({
  selector: 'app-form',
  templateUrl: './form.component.html',
  styleUrls: ['./form.component.scss'],
})
export class FormComponent implements OnInit {
  isFabListOpen = false

  toggleFab(): void {
    this.isFabListOpen = !this.isFabListOpen
    console.log('lol')
  }

  constructor() {}

  ngOnInit() {}

}

form.component.scss

ion-fab {
  position: fixed;
  left: 84%;
  float: right;
}

ion-fab-list {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  width: 350px;
  right: 130px;
}

form.component.html

<ion-fab horizontal="end" vertical="bottom" slot="fixed" [activated]="isFabListOpen">
  <ion-fab-button color="light" (click)="toggleFab()">
    <ion-icon name="arrow-dropleft"></ion-icon>
  </ion-fab-button>
  <ion-fab-list side="top" [hidden]="isFabListOpen">
    <!-- <ion-fab-button color="light">
      <ion-icon name="logo-facebook"></ion-icon>
    </ion-fab-button>
    <ion-fab-button color="light">
      <ion-icon name="logo-twitter"></ion-icon>
    </ion-fab-button>
    <ion-fab-button color="light">
      <ion-icon name="logo-vimeo"></ion-icon>
    </ion-fab-button> -->
    <form action="">
      <ion-item>
        <ion-label>quote</ion-label>
        <ion-input type="text" placeholder="Awesome Input"></ion-input>
      </ion-item>
      <ion-item>
        <ion-label>author</ion-label>
        <ion-input type="text" placeholder="Awesome Input"></ion-input>
      </ion-item>
      <ion-item>
        <ion-label>author</ion-label>
        <ion-input type="text" placeholder="Awesome Input"></ion-input>
      </ion-item>
      <ion-item>
        <ion-label>day</ion-label>
        <ion-datetime displayFormat="DD MM YY" placeholder="Leave empty to select today"></ion-datetime>
      </ion-item>
      <ion-button>
        Save
      </ion-button>
    </form>
  </ion-fab-list>
</ion-fab>


The fab list should still remain even when clicking on the fabs or components but instead close when clicked.

Answer №1

If you click fast, you can instantly restore another fabulous look with the same information as before. It'll seem like it never left! 😊

Answer №2

Eliminate the use of toggleFab() function on the button as it is redundant when using ion-fab-button. The functionality of opening and closing remains the same without the need for an extra function call. Additionally, you can omit the activated attribute unless specifically required elsewhere since its default value is false.

  1. Clicking on ion-fab-button updates isFabListOpen & activated to true
  2. Fab opens
  3. toggleFab() triggers and toggles
    this.isFabListOpen = !this.isFabListOpen
  4. isFabListOpen & activated are then set to false
  5. Modal is closed

Answer №3

Here is an example of how I used JavaScript to achieve this:

<ion-fab class="remote_controller" vertical="bottom" horizontal="center" slot="fixed">
  <ion-fab-button>
    <ion-icon name="game-controller"></ion-icon>
  </ion-fab-button>
  <ion-fab-list side="top">
    <ion-fab-button id="up" onclick="stop_close(this)">
      <ion-icon name="caret-up"></ion-icon>
    </ion-fab-button>
  </ion-fab-list>
  <ion-fab-list side="bottom">
    <ion-fab-button id="down" onclick="stop_close(this)">
      <ion-icon name="caret-down"></ion-icon>
    </ion-fab-button>
  </ion-fab-list>
  <ion-fab-list side="start">
    <ion-fab-button id="left" onclick="stop_close(this)">
      <ion-icon name="caret-back"></ion-icon>
    </ion-fab-button>
  </ion-fab-list>
  <ion-fab-list side="end">
    <ion-fab-button id="right" onclick="stop_close(this)">
      <ion-icon name="caret-forward"></ion-icon>
      </ion-icon>
    </ion-fab-button>
  </ion-fab-list>
</ion-fab>

Additionally, I included the following script:

<script>
  function stop_close(event){
    $('.remote_controller')[0].activated = false;

    //perform actions based on the button
  }
</script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular 2+ interactive popup with timer and automatic redirection

When making a request on mongodb, I need to display a modal window with an hourglass while the request is loading. The modal window should disappear once the request is finished, and if possible, redirect to another route. Technologies Used: Angular 2+, N ...

Setting up Firebase in an NX Workspace

Looking for a way to set up an Nx Workspace with Firebase that can deploy multiple applications within the monorepo. Ideal file structure would resemble something like this: To deploy the various applications, hoping to pass a config argument to the fireb ...

What steps are involved in launching an outdated Angular project?

Tasked with reviving an old Angular client in my company, I found myself grappling with outdated files and missing configurations. The lack of package.json, package-lock.json, and angular.json added to the confusion, while the presence of node modules in t ...

Having trouble with Angular 2 @input binding?

Parent module: import {NgModule} from '@angular/core'; import {SharedModule} from "app/shared/shared.module.ts"; import {HeaderComponent} from './header.component'; import {UserinfoComponent} from './userinfo.component'; imp ...

Issue with Angular2 Router: No routes were found for the specified path ''

I have set up the Angular2 Router in the following way: import { provideRouter, RouterConfig } from '@angular/router'; import { Page2} from './page2'; const routes: RouterConfig = [ { path: 'page2', component: Page2 } ]; ...

Converting JSON into Typescript class within an Angular application

As I work on my app using angular and typescript, everything is coming together smoothly except for one persistent issue. I have entity/model classes that I want to pass around in the app, with data sourced from JSON through $resource calls. Here's ...

Provide a boolean value of true or false to indicate whether all delete operations were successfully completed

Currently, I am using Sequelize, GraphQL, and Typescript for my coding. Within my database, I have two tables named RecordInformation and OtherDescription. The RecordInformation table contains a foreign key called "OtherID" which references the OtherDescri ...

Instructions on transferring a sqlite database from ionic1 and saving it to an external storage device

My Ionic1 app is live, but I am facing some serious issues with SQLite where data is not getting updated in different tables. I am looking for a way to extract the SQLite database from the app and save it to external storage using Ionic1 and AngularJS. A ...

Finding the precise Time zone with date-fns: A comprehensive guide

I've implemented a date pipe using the date-fns library for formatting dates. Here is the code: date.pipe.ts import { Pipe, PipeTransform } from '@angular/core'; import { format } from 'date-fns'; @Pipe({ name: 'formatDate ...

Implementing Angular2 with Router in a Docker Container with Nginx Deployment

I am facing a challenge with deploying my Angular 2 application that utilizes the router capabilities of the framework while serving it with nginx inside a docker container. The file structure of the angular app created by angular-cli looks like this: ./ ...

Encountering Error with NodeJS Typescript: Issue with loading ES Module when running sls offline command

I have come up with a unique solution using NodeJS, Typescript, and Serverless framework to build AWS Lambdas. To debug it locally in VS Code, I use the serverless-offline library/plugin. You can find my project on GitHub here However, when I run the comm ...

After calling sequelize.addModels, a Typescript simple application abruptly halts without providing any error messages

My experience with Typescript is relatively new, and I am completely unfamiliar with Sequelize. Currently, I have only made changes to the postgres config in the .config/config file to add the dev db configuration: export const config = { "dev" ...

Angular device redirection allows you to automatically redirect users based on the device

Currently in my Angular project, I am attempting to dynamically redirect users based on their device type. For example, if the user is on a Web platform, they will be redirected to www.web.com. If they are on an Android device, they should go to www.androi ...

Tips for continuously running a loop function until retrieving a value from an API within a cypress project

Need help looping a function to retrieve the value from an API in my Cypress project. The goal is to call the API multiple times until we receive the desired value. let otpValue = ''; const loopFunc = () => { cy.request({ method: &ap ...

The 'React' namespace does not contain the exported members 'ConsumerProps' or 'ProviderProps'

Is it possible to install this library in Visual Studio with React version 15.0.35? Are there any other libraries that are compatible with this specific React version? import * as React from 'react'; import { RouteComponentProps, NavLink } from ...

Exploring the power of async/await and promise in TypeScript

I'm puzzled as to why the return type string in this method is showing up as a red error: exportPageAsText(pageNumber: number): string { (async () => { const text = await this.pdfViewerService.getPageAsText(pageNumber); ...

Limit the outcomes of the Ionic timepicker

Currently, I am utilizing the ionic datetime feature. However, instead of receiving just the hours, minutes, and seconds, the result I am getting looks like this 2020-10-05T00:00:27.634+07:00. What I actually require from this output is only 00:00:27. Is ...

Defining a TypeScript interface specifically tailored for an object containing arrow functions

I encountered an issue while trying to define an interface for the structure outlined below: interface JSONRecord { [propName: string]: any; } type ReturnType = (id: string|number, field: string, record: JSONRecord) => string export const formatDicti ...

Combining multiple 'Eithers' and 'Promises' in fp-ts: A guide to piping and chaining operations

Recently, I began working with fp-ts and wanted to create a method with functional-like behavior that would: Parse a bearer token Verify the validity of the user using the parsed token import { Request } from 'express'; import { either } from & ...

Error encountered when creating a new project using ASP.NET Core (.NET 5) and Angular 11

When I start a new ASP.NET Core Web API + Angular project in Visual Studio by using: dotnet new angular, it sets up a .NET 5 project with an Angular 8.2 project in the ClientApp folder. After hitting F5, everything runs smoothly. However, I want to work ...