]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Add fallbackPlacement option for Tooltip and Popover
authorJohann-S <johann.servoire@gmail.com>
Fri, 5 May 2017 19:22:55 +0000 (21:22 +0200)
committerJohann-S <johann.servoire@gmail.com>
Sun, 14 May 2017 09:41:19 +0000 (11:41 +0200)
docs/components/popovers.md
docs/components/tooltips.md
js/src/dropdown.js
js/src/tooltip.js

index bc3f9333f7b7fefe08287f88e42470255c7077e9..e73f17d4649dac9fc02d91f59bcd500b52c9b93b 100644 (file)
@@ -264,6 +264,13 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap
       <td>0</td>
       <td>Offset of the popover relative to its target. For more information refer to Popper.js's <a href="https://popper.js.org/popper-documentation.html#modifiers..offset.offset">offset docs</a>.</td>
     </tr>
+    <tr>
+      <td>fallbackPlacement</td>
+      <td>string | array</td>
+      <td>['top', 'right', 'bottom', 'left']</td>
+      <td>Allow to specify which position Popper will use on fallback. For more information refer to
+      Popper.js's <a href="https://popper.js.org/popper-documentation.html#modifiers..flip.behavior">behavior docs</a></td>
+    </tr>
   </tbody>
 </table>
 
index 85e5385f56896142dfe80539bc504ce280993d61..7b3133c0e2931b90c7a04a596a035ae36f339a78 100644 (file)
@@ -242,6 +242,13 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap
       <td>0</td>
       <td>Offset of the tooltip relative to its target. For more information refer to Popper.js's <a href="https://popper.js.org/popper-documentation.html#modifiers..offset.offset">offset docs</a>.</td>
     </tr>
+    <tr>
+      <td>fallbackPlacement</td>
+      <td>string | array</td>
+      <td>['top', 'right', 'bottom', 'left']</td>
+      <td>Allow to specify which position Popper will use on fallback. For more information refer to
+      Popper.js's <a href="https://popper.js.org/popper-documentation.html#modifiers..flip.behavior">behavior docs</a></td>
+    </tr>
   </tbody>
 </table>
 
index 71247728a3a3a3eab5729514d7150acc6bb4443a..1da2098ddf9679defa84cfc8245a2617c40ad3e8 100644 (file)
@@ -157,7 +157,8 @@ const Dropdown = (($) => {
             offset : context._config.offset
           },
           flip : {
-            enabled : context._config.flip
+            enabled : context._config.flip,
+            behavior : [AttachmentMap.TOP, AttachmentMap.BOTTOM]
           }
         }
       })
index d50ddbb3e89b8eb461028452ded17bc495054b16..eb517252e0f95dc4920005779b7e819d993a2378 100644 (file)
@@ -36,32 +36,18 @@ const Tooltip = (($) => {
   const CLASS_PREFIX        = 'bs-tooltip'
   const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
 
-  const Default = {
-    animation   : true,
-    template    : '<div class="tooltip" role="tooltip">'
-                + '<div class="arrow"></div>'
-                + '<div class="tooltip-inner"></div></div>',
-    trigger     : 'hover focus',
-    title       : '',
-    delay       : 0,
-    html        : false,
-    selector    : false,
-    placement   : 'top',
-    offset      : 0,
-    container   : false
-  }
-
   const DefaultType = {
-    animation   : 'boolean',
-    template    : 'string',
-    title       : '(string|element|function)',
-    trigger     : 'string',
-    delay       : '(number|object)',
-    html        : 'boolean',
-    selector    : '(string|boolean)',
-    placement   : '(string|function)',
-    offset      : '(number|string)',
-    container   : '(string|element|boolean)'
+    animation           : 'boolean',
+    template            : 'string',
+    title               : '(string|element|function)',
+    trigger             : 'string',
+    delay               : '(number|object)',
+    html                : 'boolean',
+    selector            : '(string|boolean)',
+    placement           : '(string|function)',
+    offset              : '(number|string)',
+    container           : '(string|element|boolean)',
+    fallbackPlacement   : '(string|array)'
   }
 
   const AttachmentMap = {
@@ -71,6 +57,22 @@ const Tooltip = (($) => {
     LEFT   : 'left'
   }
 
+  const Default = {
+    animation           : true,
+    template            : '<div class="tooltip" role="tooltip">'
+                        + '<div class="arrow"></div>'
+                        + '<div class="tooltip-inner"></div></div>',
+    trigger             : 'hover focus',
+    title               : '',
+    delay               : 0,
+    html                : false,
+    selector            : false,
+    placement           : 'top',
+    offset              : 0,
+    container           : false,
+    fallbackPlacement   : [AttachmentMap.TOP, AttachmentMap.RIGHT, AttachmentMap.BOTTOM, AttachmentMap.LEFT]
+  }
+
   const HoverState = {
     SHOW : 'show',
     OUT  : 'out'
@@ -289,6 +291,9 @@ const Tooltip = (($) => {
           modifiers : {
             offset : {
               offset : this.config.offset
+            },
+            flip : {
+              behavior : this.config.fallbackPlacement
             }
           },
           onCreate : (data) => {