Comments (3)
I achieved the result I wanted to say by adding 4 different points. I mark it below.
Thus, if we add the "data-toggle-childs
" attribute to a trigger element containing "data-target-outside
", the bottom elements of the trigger will not play an active role in both closing and opening. Especially the "mouseover
" event caused great problems when you hover the mouse between the child and it parents. In this way, i have solved this.
In fact, I have found and corrected a shortcoming in coding on this occasion. You check the line going to "data-toggle-state
" and block the "data-toggle-outside
" feature. But in a "dropdown menu
", users do not want the menu to close when they return cursor to the trigger. (All this I say to the ":hover
" action)
This is exactly that part: if(event.relatedTarget && event.relatedTarget.closest("[" + TARGET_STATE + '="true"]'))return;
Places I've added
Specified as "// Added"
var ARROWS = dataset("arrows"),
CHECKED = "aria-checked",
...
...
MODAL = dataset("modal"),
OUTSIDE = dataset("outside"),
// Added
CHILDS = dataset("childs"),
var documentEventHandler = function documentEventHandler(event) {
...
...
// Added
if (element.hasAttribute(CHILDS) && element !== eTarget && element.contains(eTarget))
{
insideTarget = true;
}
var init = (function () {
...
...
triggerList.forEach(function (trigger) {
trigger.addEventListener(trigger.getAttribute(EVENT) || "click", function (event) {
event.preventDefault();
// Added
if(trigger.hasAttribute(CHILDS))
{
if( event.target !== trigger && event.relatedTarget === trigger || event.target === trigger && event.relatedTarget && trigger.contains(event.relatedTarget) )return;
}
// Added
if(event.relatedTarget && event.relatedTarget.closest("[" + TARGET_STATE + '="true"]'))return;
<section>
<div id="el-1" data-toggle-class="active" data-toggle-outside data-toggle-childs>
CLICK ME ------------------------------> Scenario 1
<p>CLICK ME</p> ---------------> Scenario 2
</div>
<span>OUTSIDE CLICK ME</span> --> Scenario 3
<section>
If there is a useful point, it is a great pleasure for me. Good luck with.
from easy-toggle-state.
Hi @ionurboz!
Thanks for taking time to add these comments. Let me check this.
from easy-toggle-state.
Well it seems it's more a dom structure issue than a missing feature.
In my opinion, if you really want to use this library, you probably shound rethink your structure.
from easy-toggle-state.
Related Issues (20)
- Can you target multiple elements? HOT 3
- Allow multiple triggers to modify a single toggle-able node HOT 5
- Multiple targets with different classes? HOT 6
- Programmatic Toggling HOT 5
- Toggling inputs HOT 10
- data-toggle-target-parent="" doesnt work with data-toggle-group=""? HOT 2
- Codepen example for simple tabs doesn't work HOT 1
- Add a default state attribute for target elements HOT 2
- Triggers don't work when loaded via XHR HOT 1
- data-toggle-trigger-off elements do not unbind HOT 1
- Toggles that target elements with data-toggle-trigger-off in them hijack focus on data-toggle-escape/data-toggle-outside
- Sample in Blazor ?
- Different class on trigger and target? HOT 10
- Toggle tabs from a select box HOT 1
- Bug with data-toggle-class-on-target HOT 3
- Using data-toggle-outside with a trigger containing another tag HOT 3
- Possible to work on hover? HOT 1
- Data-Toggle-Trigger-Off Not Working With CSS Selectors HOT 5
- Feedback HOT 2
- Browser support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from easy-toggle-state.