GithubHelp home page GithubHelp logo

cferdinandi / drop Goto Github PK

View Code? Open in Web Editor NEW
77.0 6.0 13.0 420 KB

A small CSS component that turns browser-native <details> elements into dropdown menus.

License: MIT License

JavaScript 45.96% CSS 17.77% HTML 35.21% HCL 1.06%
dropdowns no-dependencies css details html html-css

drop's Issues

Example without UI

I'm trying to implement Drop into my Tailwind CSS app.
I would like to use the Tailwind CSS classes for styling and Drop for opening and closing the dropdown. I am looking for an example like Tabby where there is an option without UI. So only using the Javascript file from Tabby. Would this be possible?

Using the code below I manage to make Drop open and close the dropdown menu.

<div class="relative">
  <details class="dropdown">
    <summary>
      <button
        class="block h-8 w-8 rounded-full overflow-hidden border-2 border-gray-600 focus:outline-none focus:border-white">
        <img class="h-full w-full object-cover"
          src="https://images.unsplash.com/photo-1487412720507-e7ab37603c6f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=256&q=80"
          alt="Your avatar">
      </button>
    </summary>
    <div class="absolute right-0 mt-2 py-2 w-48 bg-white rounded-lg shadow-xl">
      <a href="#" class="block px-4 py-2 text-gray-800 hover:bg-indigo-500 hover:text-white">Account settings</a>
      <a href="#" class="block px-4 py-2 text-gray-800 hover:bg-indigo-500 hover:text-white">Support</a>
      <a href="#" class="block px-4 py-2 text-gray-800 hover:bg-indigo-500 hover:text-white">Sign out</a>
    </div>
  </details>
</div>

Now I would like to remove the arrow from the details. Anny suggestion is welcome.

image

Update NPM deps and switch to lib-sass

package.json

"gulp": "^3.9.0",
"node-fs": "^0.1.7",
"del": "^1.2.0",
"lazypipe": "^0.2.4",
"gulp-plumber": "^1.0.1",
"gulp-flatten": "^0.0.4",
"gulp-tap": "^0.1.3",
"gulp-rename": "^1.2.2",
"gulp-header": "^1.2.2",
"gulp-footer": "^1.0.5",
"gulp-watch": "^4.2.4",
"gulp-livereload": "^3.8.0",
"gulp-jshint": "^1.11.1",
"jshint-stylish": "^2.0.1",
"gulp-concat": "^2.6.0",
"gulp-uglify": "^1.2.0",
"karma": "^0.12.37",
"gulp-karma": "^0.0.4",
"karma-coverage": "^0.4.2",
"jasmine": "^2.3.1",
"karma-jasmine": "^0.3.6",
"karma-phantomjs-launcher": "^0.2.0",
"karma-spec-reporter": "^0.0.19",
"karma-htmlfile-reporter": "^0.2.1",
"gulp-sass": "^2.0.3",
"gulp-minify-css": "^1.2.0",
"gulp-autoprefixer": "^2.3.1",
"gulp-svgmin": "^1.1.2",
"gulp-svgstore": "^5.0.2",
"gulp-markdown": "^1.0.0",
"gulp-file-include": "^0.11.1"

gulpfile.js

.pipe(sass({
    outputStyle: 'expanded',
    sourceComments: true
}))

Fix event listener

} else if ( toggle !== document.documentElement && toggle.parentNode.hasAttribute( 'data-dropdown' ) ) {

becomes…

} else if ( toggle !== document.documentElement && getClosest(toggle, '[data-dropdown]') ) {

Close dropmenus when the document is clicked

Any way you could add the ability to close the dropdowns when the document is clicked?

This is how the dropdowns behave with Twitter's Bootstrap framework.

Thanks for sharing your code.

Add optimize js

package.json

"gulp-optimize-js": "^1.0.2",

gulpfile.js

var optimizejs = require('gulp-optimize-js');

    var jsTasks = lazypipe()
        .pipe(header, banner.full, { package : package })
        .pipe(optimizejs)
        .pipe(gulp.dest, paths.scripts.output)
        .pipe(rename, { suffix: '.min' })
        .pipe(uglify)
        .pipe(optimizejs)
        .pipe(header, banner.min, { package : package })
        .pipe(gulp.dest, paths.scripts.output);

Drop Jumbo (with Astro Navbar). Added sub-links not working in ProcessWire CMS

I'm trying to use Drop Jumbo (with Astro Navbar) with ProcessWire for a project.

The static basis is:

Menu
    <ul class="nav-navbar">

        <li class="dropdown-jumbo" data-dropdown>
            <a href="FALLBACK-URL.com">
                Link
                <span class="dropdown-show">+</span>
                <span class="dropdown-hide">-</span>
            </a>
            <div class="dropdown-menu-jumbo" data-dropdown-menu>
                <div class="container">
                    <div class="grid-three-fourths float-center">                                    
                        <ul>
                            <li><a href="#">Sub-link</a></li>                                    
                        </ul>  
                    </div>                                  
                </div>
            </div>
        </li>

    </ul>

</div>

So, I've replaced divs and texts (only) with an ul, lists and anchors (if compared to the demo).

Perhaps because of this (an active class being applied to a second-level anchor(?)) or something else, when I click on a sub-link in the drop-down menu, it doesn't load the page targeted by the anchor/link (but the URL is fine).
There is the following message in Firebug's Console(?):
"TypeError: i is null

...e.classList.toggle(o.toggleActiveClass),i.classList.toggle(o.contentActiveClass)..."

The fallback URL is the first sub-link URL.

Grandchild items

Hey Chris,

I just installed the version 5.0.0 of drop for a new project and I noticed that grandchild menu items are not receiving the same treatment as parent menu items. In the following markup I have a grandchild item:

...
    <li class="dropdown">
        <a href="FALLBACK-URL.com">Dropdown 1</a>
        <div class="dropdown-menu dropdown-right">
            <ul>
                <li><a href="#">Item 1</a></li>
                <li><a href="#">Item 2</a></li>
                <li><a href="#">Item 3</a>
                    <ul>
                        <li><a href="#">Grandchild Item 1</a></li>
                    </ul>
                </li>
                <li><a href="#">Item 4</a></li>
            </ul>
        </div>
    </li>
...

When I am clicking on the list-item (Item 3) the child element UL is not receiving and active state <ul class="active"> . I tested the difference on the same project by installing an older version of drop (4.3.1) and was able to achieve an active state on nested items.

Thanks again for the good work!

Update Drop expand/collapse styling

/**
 * Styling for expand/collapse icons
 */
.dropdown-basic > a .dropdown-show,
.dropdown-basic > a .dropdown-hide,
.js-drop .dropdown-basic > a.active .dropdown-show {
    display: none;
    visibility: hidden;
}

.js-drop .dropdown-basic > a .dropdown-show,
.js-drop .dropdown-basic > a.active .dropdown-hide {
    display: inline-block;
    visibility: visible;
}

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.