.on('click.zf.trigger', function(e) {
_this._setCurrentAnchor(this);
- if (_this.options.forceFollow && hasTouch && _this.options.hover) {
- var hasClicked = $(this).attr('data-is-click') === true;
- if (hasClicked === false && _this.$element.attr('aria-hidden') === 'true') {
- e.preventDefault();
- }
+ if (_this.options.forceFollow === false) {
+ // if forceFollow false, always prevent default action
+ e.preventDefault();
+ } else if (hasTouch && _this.options.hover && _this.$element.hasClass('is-open') === false) {
+ // if forceFollow true and hover option true, only prevent default action on 1st click
+ // on 2nd click (dropown opened) the default action (e.g. follow a href) gets executed
+ e.preventDefault();
}
});
*/
closeOnClick: false,
/**
- * Boolean to force overide the clicking of toggle link (href) to perform default action, on second touch event for mobile.
+ * If true the default action of the toggle (e.g. follow a link with href) gets executed on click. If hover option is also true the default action gets prevented on first click for mobile / touch devices and executed on second click.
* @option
* @type {boolean}
* @default true
<p>This test is supposed to show a linked dropdown toggle <strong>with enabled hover option</strong>.<br>On desktop mouseover opens the dropdown pane and click opens the link's href.<br>On mobile the first touch opens the dropdown pane and the second touch (while still opened) opens the link's href.</p>
- <div class="button-group">
+ <div class="stacked-for-small button-group">
<a href="https://www.google.com" class="button" data-toggle="example-dropdown-1">Linked Hoverable Dropdown</a>
<button type="button" class=" secondary button" data-toggle="example-dropdown-2">Hoverable Dropdown</button>
<button type="button" class=" secondary button" data-toggle="example-dropdown-3">Clickable Dropdown</button>
This is a clickable dropdown.
</div>
+ <p>If having set the option <code>forceFollow:false</code> the default action gets always prevented and thus the linked dropdown toggle will never open the link's href.</p>
+
+ <a href="https://www.google.com" class="button" data-toggle="example-dropdown-4">Linked Dropdown with forceFollow false</a>
+
+ <div class="dropdown-pane" id="example-dropdown-4" data-dropdown data-hover="true" data-hover-pane="true" data-force-follow="false">
+ This is a linked hover dropdown with forceFollow set false. The link's href gets never opened no matter how often you click.
+ </div>
+
</div>
</div>
</div>