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

Ionic 2 - (feat) FAB button fixed positions

Open WHarris22 opened this issue 10 years ago • 20 comments

Version Ionic 2.x

Current Behaviour If you see this plnkr you will notice a scrollable list with a FAB button positioned bottom right, but as soon as you start scrolling it moves up with the list content.

Feature Description I think it would be useful to have the option to make a FAB button fixed so that in my example we can optionally force it to stay bottom right of the content.

This might be as simple as changing the CSS position from absolute to fixed but then there are issues in IOS for example when tabs are at the bottom of the view because using fab-bottom and fab-right place it over the tabs.

CLI Ionic info

Cordova CLI: 5.4.0 Gulp version: CLI version 3.8.11 Gulp local: Local version 3.9.1 Ionic Framework Version: 2.0.0-beta.4 Ionic CLI Version: 2.0.0-beta.24 Ionic App Lib Version: 2.0.0-beta.14 OS: Windows 8.1 Node Version: v4.4.2

WHarris22 avatar Apr 20 '16 13:04 WHarris22

I don't think this is actually a feature, but more a bug?

dylanvdmerwe avatar Apr 20 '16 14:04 dylanvdmerwe

Depends on what you are saying, if by bug you mean it should always be positioned fixed to the viewport then I would have to disagree with you.

Sometimes the FAB button may define an action for a specific element in the view in which case you want it to position absolute to that element so it follows it as you scroll, in other cases you want it to define an action that isn't specific to just one element in which case it is good to position it fixed to the viewport.

WHarris22 avatar Apr 20 '16 14:04 WHarris22

@dylanvdmerwe So yeah with android there is kind of two ways that fab buttons are used, Attached to certain elements in the ui (you can see this in some places on the youtube app for android) and then where the fab button is absolute in the bottom right corner of the viewport. So i would define this as a feature since the current default behavior is not "wrong" in general but just wrong for certain use cases.

jgw96 avatar Apr 20 '16 15:04 jgw96

Simply Putting position:fixed on the button works

prijindal avatar Apr 21 '16 10:04 prijindal

@prijindal thats correct but like I said in the question if you have a tab bar at the bottom using the FAB positioning attributes e.g. fab-bottom and fab-right will then place the button over the tab bar.

Again I know the resulting problem of position:fixed can be resolved using CSS rules and so on, but call me lazy it would be nice for the framework to simplify it for me and others who are equally as lazy :)

WHarris22 avatar Apr 21 '16 11:04 WHarris22

@WHarris22 Hey! Sorry should have mentioned this earlier but just thought about it. You can the the fab-fixed attribute on the fab button to give it a position: fixed style! I will update the docs to show this. Closing now as this will solve the issue.

jgw96 avatar Apr 25 '16 18:04 jgw96

@jgw96 This does not resolve the issue @WHarris22 mentioned where tabs are at the bottom. I think the best solution where it will work with tabs and stick to the container is to use the ion-fixed element, which isn't documented yet. Something like this:

<ion-navbar *navbar>
  <ion-title>Fixed Buttons</ion-title>
</ion-navbar>

<ion-content padding>
  <button block>
    Normal Button
  </button>

  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam consequat ullamcorper ex sed ultricies. Nunc vitae risus in urna luctus ullamcorper. Etiam vitae augue vestibulum, lobortis leo eget, blandit ante. Integer eget nibh a ante eleifend venenatis nec id lectus. Curabitur vel condimentum dui. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nunc pulvinar mollis elit mattis congue. Morbi sem lectus, dictum id sollicitudin sed, ullamcorper non velit.</p>

  <p>Interdum et malesuada fames ac ante ipsum primis in faucibus. Etiam lobortis sit amet eros placerat venenatis. Etiam lorem elit, elementum a odio sed, maximus auctor lacus. Integer purus augue, vulputate ac gravida non, viverra maximus turpis. Praesent ut libero turpis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Ut hendrerit interdum mauris id placerat. Mauris ac turpis dui. Quisque eget lorem enim. Sed elementum, urna tempor euismod malesuada, ante lorem semper odio, non iaculis nisl velit at dui. Ut vestibulum lorem justo, eu ultrices felis elementum sed. Fusce sed nisl auctor, suscipit lacus quis, hendrerit arcu. Ut laoreet sapien non sollicitudin egestas. Sed volutpat odio non libero porta fringilla. Praesent felis magna, lacinia vel turpis a, egestas hendrerit ligula. Maecenas sed turpis sit amet est fringilla volutpat et ac sapien.</p>

  <p>Sed rutrum sed odio in fringilla. Morbi sagittis nisl eros, vitae porttitor turpis malesuada in. Sed sed elit molestie, venenatis nulla at, sodales magna. Mauris a magna eget tellus convallis pulvinar. Ut et mauris purus. Aliquam erat volutpat. Fusce pellentesque felis in porta commodo. Donec aliquam viverra arcu, eget egestas sem ullamcorper ut. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque condimentum ligula vel turpis auctor finibus. Quisque bibendum eu justo eget luctus. Integer non sapien velit.</p>

  <p>Quisque rhoncus metus augue, non mollis dui posuere ac. Donec aliquet cursus ante at euismod. In in convallis nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse a rhoncus metus. Ut quam elit, faucibus ac maximus eget, hendrerit fringilla nunc. Maecenas volutpat, risus in lobortis iaculis, magna mi convallis mauris, in cursus nulla eros vel neque. Ut consequat iaculis semper. Suspendisse tempus ornare sem, sed sagittis urna iaculis euismod. Maecenas rutrum urna quam, a pulvinar ante euismod ut. Duis eget velit mi. Aliquam laoreet lacus luctus risus posuere placerat eu ultrices nunc. Quisque ut tellus in risus mattis elementum luctus vel ipsum.</p>

  <p>Ut et fermentum odio. Etiam id porta ex. Proin ex enim, aliquet nec tempor id, vulputate eu felis. Duis consectetur ex nulla, non hendrerit neque finibus a. Donec scelerisque finibus imperdiet. Pellentesque viverra, risus eget ultrices lobortis, orci eros sagittis purus, quis sollicitudin elit erat sed ligula. Maecenas non porttitor erat. Aenean odio est, fermentum sed arcu in, gravida rhoncus justo. In purus felis, tristique sed aliquet id, vehicula ut est. Morbi ut ornare turpis. In pulvinar sem a odio tristique suscipit ut placerat diam. Pellentesque sollicitudin luctus venenatis. In commodo ante ipsum, ut vehicula diam feugiat in. Suspendisse potenti.</p>

  <button block>
    Normal Button
  </button>

  <button fab fab-left fab-bottom danger fab-fixed>
    <ion-icon name="add"></ion-icon>
  </button>

  <ion-fixed class="fixed-div">
    <button fab fab-right fab-bottom dark>
      <ion-icon name="add"></ion-icon>
    </button>
  </ion-fixed>
</ion-content>

<style>
  .fixed-div {
    right: 0;
    bottom: 0;
  }
</style>

which results in the following:

screen shot 2016-04-25 at 2 32 58 pm

Going to reopen this because we either need to add something for fab specifically to get this to work (probably part of https://github.com/driftyco/ionic/issues/5069), or need to document ion-fixed better and include this as a use case.

brandyscarney avatar Apr 25 '16 18:04 brandyscarney

When using fab-fixed with a button that is placed above an ion-list that uses ngFor the button is positioned correctly in chrome but scrolls with the list in the iOS Simulator until the list stopped scrolling.

frederikschubert avatar May 21 '16 21:05 frederikschubert

@brandyscarney Guys please fix this.. I'm waiting since beta 5 :-)

TheMohanraj avatar Jun 16 '16 05:06 TheMohanraj

If you are adding the FAB fixed it should follow the Material design rule: Don’t block the floating action button (find 2 videos showing the demo)

If we speak about ionic2, it its the snackbar (which is called toast) that will block the FAB, so a workaround is required so the FAB is translated up when a snackbar appears from bottom so they don't overlap.

Also very excited about expanding the FAB into a list of actions like this example with contacts.

oktav777 avatar Jun 28 '16 12:06 oktav777

There is another issue I've just come across and would like to make you aware of when using the fab-fixed attribute (along with what @brandyscarney posted in an image a few comments ago)...

If I include the ion-refresher inside the page's ion-content which is a common case when dealing with lists, the fab button will drag down with the content as you pull down to refresh. I guess this may also be something in relation to what @InfinityOne said about don't block the FAB.

Thought I would include a screenshot to help get my point across :)

fab-issue

WHarris22 avatar Jul 06 '16 13:07 WHarris22

Same issue here , here is my code

<ion-content class="schedule">

 <ion-refresher (ionRefresh)="doRefresh($event)">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <ion-list >
    <ion-item  *ngFor="let campaign of campaignData.data" >
           // some application UI
    </ion-item>
  </ion-list>

      <button fab fab-fixed fab-bottom fab-right (click)="presentAddCampaign()">
      <ion-icon name="md-add" is-active="false"></ion-icon>
    </button>
</ion-content>

I also have ion refresher component in my page. when i pull down list to refresh list fab icon goes down

ashutosh-akss avatar Jul 21 '16 14:07 ashutosh-akss

Is there a workaround to get this thing floating at fixed position no matter what user does or what content is displayed?

cloudscape-germany avatar Aug 02 '16 14:08 cloudscape-germany

Change position property from absolute to relative.

Do little manual padding and margin and you are ready to go.

.button-fab { position: relative !important; margin-top: 7%; }

rohngonnarock avatar Aug 14 '16 19:08 rohngonnarock

I think put your button inside a ion-footer is the unique way to keep it fixed to bottom on ios view.

felipeands avatar Sep 07 '16 22:09 felipeands

Hello all! Thanks for using Ionic! This will be in the beta.12 release.

jgw96 avatar Sep 21 '16 15:09 jgw96

Just keep the ion-footer out of the ion-content

divyanshuchat avatar Jan 19 '17 04:01 divyanshuchat

Hey, I got that issue too on Ionic V.2.2.3. I have a <ion-fab><button></button></ion-fab> element, and this element is inside a <div> that belongs to a <ion-segment> element (this segment is split in 4 areas, so I use a div for each segment), and I'm using this ion-fab just on one segment, but it scrolls with the content (I have a cards list), this is my code:

<ion-fab bottom right> <button (click)="goToClientsList()" ion-fab color="secondary"> <ion-icon name="add"></ion-icon> </button> </ion-fab>

citerio avatar May 24 '17 14:05 citerio

Problem solved. The ion-tab component must be a direct child of ion-content, so I use the *ngIf property on the button for hidding/showing, this way I can show the ion-fab component on the required segment div.

Thanks.

citerio avatar May 24 '17 15:05 citerio

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Sep 02 '18 22:09 ionitron-bot[bot]