Giter Club home page Giter Club logo

react-router-navlink-inactiveclassname's Introduction

react-router-navlink-inactiveclassname

A fork of react router 4's Link component that supports an inactiveClassName attribute.

This relates to the NOFIX issue I raised on React Router's github: [TBD] strongly believe the NOFIX was an incorrect response for the following reasons:

When using a global/functional CSS strategy like Tachyons is it critical we do not rely on selector specificity and className order. At present, however, to style active and inactive NavLinks we do this:

<NavLink className="f5 black" activeClassName="red" />

Which renders as

<a class="f5 black" /> // <-- inactive
<a class="f5 black red" /> // <-- active

This happens to work because .red is after .black in the Tachyons style sheet. But if I'd chosen .navy instead of .black - which happens to be after .red - then the active style does nothing.

As you can see this is inherently brittle and furthermore browsers are not required by the W3C spec to honour class order. You can get around this by creating custom css classes and invoking !important or increased specificity but this breaks a core principle of functional css.

Preferred would be:

<NavLink className="f5" activeClassName="red" inactiveClassName="black" />

Which would render as

<a class="f5 black" /> // <-- inactive
<a class="f5 red" /> // <-- active

giving you the results you'd expect.

Side note: from a general point of view, I've found that adding classes - as opposed to switching them - generally isn't scalable in a wide variety of cases not just Tachyons.

react-router-navlink-inactiveclassname's People

Contributors

jofarnold avatar

Watchers

James Cloos avatar  avatar

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.