Improved Bootstrap Modals UX on Mobile Phones

Improved Bootstrap Modals UX on Mobile Phones
Project: bootstrap-fs-modal
Author: keaukraine
Fork: Fork on GitHub
License: MIT

Bootstrap Mobile FullScreen Modal

A simple way to improve the UX of Bootstrap 3 modals on mobile phones.

*Note: The bootstrap 4 version of this plugin is available here – https://github.com/keaukraine/bootstrap4-fs-modal*

Regular Bootstrap 3 modals (with a lot of content) on mobile devices can cause additional scrolling to get to the bottom buttons of the modal.

Fullscreen modal provides a more native user experience on mobile phones, here is a side-by-side comparison of regular and fullscreen models:

Regular Bootstrap Modal on Phone
Fullscreen Bootstrap Modal on Phone

Fullscreen modal does not affect modals in large viewports and applies these styles only on mobile devices.

The live demo page is here – https://keaukraine.github.io/bootstrap-fs-modal/

How to Use

You can obtain the plugin either from GitHub or from npm, the package name is bootstrap-fs-modal.

First, include CSS and JS from dist folder:

<link href="dist/css/fs-modal.min.css" rel="stylesheet">
...
<script src="dist/js/fs-modal.min.js"></script>

Then, you have to add the CSS class modal-fullscreen to models which you want to work full-screen.

The plugin can create either text or icon buttons.
For buttons to appear as icons, you will need to make a little modification of HTML. The plugin processes all buttons in the footer except the ones with data-dismiss="modal" attributes (close button, which will be always added automatically), and adds them either as text or as icon buttons. Icon for the button can be either Glyphicon of Font Awesome icon and is set by data-glyphicon or data-faicon attribute. If one of these attributes is set, it will add a button with the provided icon. If the icon attribute is not set or empty, it will create a text button instead. The plugin will try to apply short text by looking for short button text in data-mobile-text the attribute and falling back to button text if the attribute is not set.

Example:

<div class="modal fade modal-fullscreen" id="modal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
...
<div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> <!-- will be skipped -->
  <button type="button" class="btn btn-default" data-glyphicon="glyphicon-refresh">Reload Data</button> <!-- Glyphicon button -->
  <button type="button" id="btnTestSettingsFAButtons" class="btn btn-default" data-faicon="fa-cog">Settings</button> <!-- Font Awesome icon button -->
  <button type="button" id="btnTestRefreshTextButtons" class="btn btn-default" data-mobile-text="Reload">Reload Data</button> <!-- text button with short text -->
  <button type="button" id="btnTestSaveTextButtons" class="btn btn-default btn-primary">Save</button> <!-- text button with default text -->
</div>

That’s all you need. JS automatically tracks show.bs.modal events and duplicates all buttons to the modal header, wiring click events to the original buttons.

Used Libraries

License

The MIT License

Copyright (c) 2017 Oleksandr Popov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  • .gitignore
  • Gruntfile.js
  • LICENSE.txt
  • README.md
  • dist
  • index.html
  • package.json
  • src
No Chnagelog!

Leave a Reply

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Scroll to Top