ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

FAB list feature: labels and backdrop options

Open Manduro opened this issue 10 years ago • 33 comments

Feature request

It would be cool if the FAB list could support labels and an optional backdrop as mentioned here: https://github.com/driftyco/ionic/issues/5069#issuecomment-172681668

Example

Manduro avatar Oct 03 '16 09:10 Manduro

+1

captaincole avatar Oct 30 '16 01:10 captaincole

screen shot 2016-10-29 at 6 45 53 pm I created a workaround for this, but the implementation is custom (you have to change the css for each individual label).

I have a fab button with two options, like so

<ion-fab right class="floating-action" (click)="addMenu()">
    <button ion-fab>
  <ion-icon name="add"></ion-icon>
</button>
<ion-fab-list side="top">
  <button ion-fab class="option" (click)="createMovement()">
    <span class="flaticon-gym-1"></span>
    <div class="fab-label fab-label-mov">Create Movement</div>
  </button>
  <button ion-fab class="option" (click)="createWorkout()">
    <span class="flaticon-people"></span>
    <div class="fab-label fab-label-work">Create Workout</div>
  </button>
  <button *ngIf="dev" ion-fab class="option" (click)="createProgram()"><ion-icon name="calendar"></ion-icon></button>
</ion-fab-list>
</ion-fab>

And then I have an attached css properties like below

.floating-action {
bottom: 65px;
z-index: 1;

.option {
    background-color: blue;
    text-align: center;
    overflow: visible;
}
.fab-label {
    position: absolute;
    background: lightslategrey;
    height: 24px;
    line-height: 16px;
    padding-left: 8px;
    padding-right: 8px;
    padding-top: 5px;
    padding-bottom: 5px;
    border-radius: 5px;
    box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.14), 0 4px 5px rgba(0, 0, 0, 0.1);
}
.fab-label-mov {
    margin-left: -90px; /* Custom for each label */
}
.fab-label-work {
    margin-left: -83px; /* Custom for each label */
}
.button-inner {
    overflow: visible; /* This makes the labels shown, overrides default ionic properties */
}
}

This should get you by for now.

captaincole avatar Oct 30 '16 01:10 captaincole

Here's what I did improving upon the work of @thielCole, making it a (kinda) drop-in replacement.

ion-fab {
    ion-fab-list button[ion-fab] {
        text-align: center;
        overflow: visible;

        div {
          position: absolute;
          right: 48px;
          background: rgba(248, 248, 248, 1);
          height: 24px;
          line-height: 16px;
          padding-left: 8px;
          padding-right: 8px;
          padding-top: 5px;
          padding-bottom: 5px;
          margin-top: 8px;
          border-radius: 5px;
          box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.14), 0 4px 5px rgba(0, 0, 0, 0.1);
        }
    }

    .button-inner {
        overflow: visible;
    }
}

And the markup (text must be in a div) :

  <ion-fab bottom right>
    <button ion-fab>
      <ion-icon name="add"></ion-icon>
    </button>
    <ion-fab-list side="top">
      <button ion-fab (click)="123()">
        <ion-icon name="book"></ion-icon>
        <div>LABEL TEXT HERE</div>
      </button>
      ...
    </ion-fab-list>
  </ion-fab>

Bouzmine avatar Nov 01 '16 01:11 Bouzmine

Quick question @Bouzmine. Did you notice that there are little transparent shapes on each button ? I cannot remove them when I am using your solution.

speedfl avatar Nov 09 '16 21:11 speedfl

untitled

Here is what I can observe

speedfl avatar Nov 11 '16 13:11 speedfl

@speedfi I don't see that, but I use the FAB list with position="top" could you tell me if it works with that setting?

Bouzmine avatar Nov 11 '16 14:11 Bouzmine

Hey! Thanks for your answer I have

It seems to be visible because of the overflow visible. I saw that you have a class .innerButton but not used in the html. Maybe it is linlked to this?

<ion-fab bottom right *ngIf="me==false">
    <button ion-fab ><ion-icon name="add"></ion-icon></button>
    <ion-fab-list side="top">
      <!-- display -->
      <button ion-fab color="primary" *ngIf="requestDisplay" (click)="display()">
        <ion-icon name="log-in"></ion-icon>
        <div>Demander de voir</div>
      </button>
    ...

What is strange is that if I put my padding left and right to 0 (on the div) it disapear. in fact it follow the size of the div. If I grow the size the padding etc it grows. Same thing if I reduce it. It is not a profile of display iin chrome because even on my app I have the same

speedfl avatar Nov 11 '16 15:11 speedfl

Here's the new version that's (I hope) fixing the issue @speedfl had : The div containing the text now has a class (label) for the CSS to be able to style it and not to style Ionic's elements (namely div.button-effect which was causing the problem). To be noted that the problem didn't appear in Safari for me (don't know why). Also added shadow which was not present in earlier version and ajusted margin-top to be more in-line with new size of ionic2.0.0-rc.3.

ion-fab {
    button {
        box-shadow: 0 4px 10px #6b6b6b;
    }

    ion-fab-list button[ion-fab] {
        text-align: center;
        overflow: visible;

        div.label {
          position: absolute;
          right: 48px;
          background: rgba(248, 248, 248, 1);
          height: 24px;
          line-height: 16px;
          padding-left: 8px;
          padding-right: 8px;
          padding-top: 5px;
          padding-bottom: 5px;
          margin-top: 8px;
          border-radius: 5px;
          box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.14), 0 4px 5px rgba(0, 0, 0, 0.1);
        }
    }

    .button-inner {
        overflow: visible;
    }
}

And the markup (text must be in a div.label) :

  <ion-fab bottom right>
    <button ion-fab>
      <ion-icon name="add"></ion-icon>
    </button>
    <ion-fab-list side="top">
      <button ion-fab (click)="CLICK HANDLER HERE">
        <ion-icon name="ICON NAME HERE"></ion-icon>
        <div class="label">LABEL TEXT HERE</div>
      </button>
      ...
    </ion-fab-list>
  </ion-fab>

Bouzmine avatar Nov 20 '16 17:11 Bouzmine

Man it is perfect !!! 👍

speedfl avatar Nov 22 '16 21:11 speedfl

Thank you so much @Bouzmine and @thielCole ! 👍

idiosyncraticee avatar Nov 25 '16 16:11 idiosyncraticee

Perfect! Thank you!

ericmorentin avatar Nov 30 '16 10:11 ericmorentin

It works great in browser and IOS devices, but in Android the labels doesn't show, anyone else having this issue?

gerhardx avatar Nov 30 '16 21:11 gerhardx

Hello @Bouzmine

Did you try to migrate to rc4? my label disappeared and I am trying to figure out what happened but not able :)

speedfl avatar Dec 17 '16 12:12 speedfl

@speedfl Does work for me, I don't know what is happening, are you on WKWebView, or just testing on your computer?

Bouzmine avatar Dec 17 '16 12:12 Bouzmine

Hello.

On my computer using ionic serve :(

speedfl avatar Dec 17 '16 12:12 speedfl

@speedfl I see the bug you're talking about, it seems to be the same as the one preventing this solution from working in Android because I can only reproduce in Chrome. Safari (macOS) and webviews in iOS are OK. I don't know what is causing this bug. Just hoping for an official solution to be release sooner than later.

Bouzmine avatar Dec 17 '16 13:12 Bouzmine

So after hours I was finally able to make this work in rc4. In fact I am using default variable of ionic for fab. This has the advantage of having (approximatively) same look on all the devices whatever the screen resolution + the container give a not opaque white screen behind the FABS.

Thanks a lot @Bouzmine for your solution. I would like to share mine if you want to migrate. Peace!

so in your html:

` <ion-fab bottom right *ngIf="showMenu" (click)="showMenuItems()">

	<button ion-fab color="primary" (click)="action1()">
	<ion-icon name="log-in"></ion-icon>
	</button>

	<button ion-fab color="primary" (click)="action2()">
	<ion-icon name="log-out"></ion-icon>
	</button>
	</ion-fab-list>
	</ion-fab>

	<div class="labelContainer" *ngIf="showMenuItem">
	<div class="container">
	<a (click)="action2"><div class="label">Label 2</div></a>
	<a (click)="action1"><div class="label">Label 1</div></a>
	</div>
	</div>`

In your css:

` .labelContainer { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(255, 255, 255, 0.5); z-index:99;

		.container{
		  position: absolute;
		  bottom: $fab-content-margin * 3.4 + $fab-size;
		  right: 20%;

		  .label{
			font-family: Corbel;
			text-align: left;
			color:white;
			background: #9991ff;
			-webkit-border-radius: 10px;
			-moz-border-radius: 10px;
			border-radius: 10px;
			padding: 7px;
			width:220px;
			margin-top: ($fab-list-margin * 2.5);
			margin-right: 0px;
			box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.14), 0 4px 5px rgba(0, 0, 0, 0.1);
		  }
		}
	  }

`

And finally in your script:

  `showMenuItems(){
      this.showMenuItem = !this.showMenuItem;
  }`

speedfl avatar Dec 22 '16 08:12 speedfl

@speedfl @gerhardx Add this to the styles noted by @Bouzmine above when your labels are invisible on Chrome:

.fab {
  contain: initial;
}

Manduro avatar Dec 22 '16 09:12 Manduro

Anyone implemented backdrop?

ozexpert avatar Feb 03 '17 16:02 ozexpert

@ozexpert yep look at my answer

speedfl avatar Feb 03 '17 17:02 speedfl