Coder Social home page Coder Social logo

Some features about easy-toggle-state HOT 3 CLOSED

twikito avatar twikito commented on May 18, 2024
Some features

from easy-toggle-state.

Comments (3)

ionurboz avatar ionurboz commented on May 18, 2024

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.

Twikito avatar Twikito commented on May 18, 2024

Hi @ionurboz!
Thanks for taking time to add these comments. Let me check this.

from easy-toggle-state.

Twikito avatar Twikito commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.