From b876809c8e36a00d1f9712f9151189e1b4f2be06 Mon Sep 17 00:00:00 2001 From: SassNinja Date: Wed, 24 Jan 2018 16:38:25 +0100 Subject: [PATCH] Add comments and rework condition to consider explicit forceFollow:false --- js/foundation.dropdown.js | 14 ++++++++------ test/visual/dropdown/linked-dropdown-toggle.html | 10 +++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/js/foundation.dropdown.js b/js/foundation.dropdown.js index 2b308efb0..0ad038b98 100644 --- a/js/foundation.dropdown.js +++ b/js/foundation.dropdown.js @@ -141,11 +141,13 @@ class Dropdown extends Positionable { .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(); } }); @@ -419,7 +421,7 @@ Dropdown.defaults = { */ 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 diff --git a/test/visual/dropdown/linked-dropdown-toggle.html b/test/visual/dropdown/linked-dropdown-toggle.html index ba9d2db50..c3ca65a05 100644 --- a/test/visual/dropdown/linked-dropdown-toggle.html +++ b/test/visual/dropdown/linked-dropdown-toggle.html @@ -16,7 +16,7 @@

This test is supposed to show a linked dropdown toggle with enabled hover option.
On desktop mouseover opens the dropdown pane and click opens the link's href.
On mobile the first touch opens the dropdown pane and the second touch (while still opened) opens the link's href.

-
+
Linked Hoverable Dropdown @@ -32,6 +32,14 @@ This is a clickable dropdown.
+

If having set the option forceFollow:false the default action gets always prevented and thus the linked dropdown toggle will never open the link's href.

+ + Linked Dropdown with forceFollow false + + +
-- 2.47.2