GithubHelp home page GithubHelp logo

Comments (3)

elboman avatar elboman commented on April 17, 2024

I understand your point, but there are a couple of reasons why we went with this setup:

  • maintain consistency between UI Router framework implementations
  • give a flexible way to handle complex DOM structures

There are cases where you don't want the active class to be attached to the UISref component because of some tricky DOM structure in your menus:

<UISrefActive class="active">
  <li className="some-menu">
    <!-- might need some nodes here -->
    <UISref to="somewhere">
      <a>Some link</a>
    </UISref>
  </li>
</UISrefActive>

I understand your concern with verbosity but you can always take advantage of React components to take care of that:

const Link = ({ to, activeClassName, children }) =>
  <UISrefActive class={activeClassName}>
    <UISref to={to}>{children}</UISref>
  </UISrefActive>;

// ...

<Link to="somestate" activeClassName="active"><button>Some link</button></Link>

or even:

import React, {createElement} from 'react';

const Link = ({ to, activeClassName, element, children }) =>
  <UISrefActive class={activeClassName}>
    <UISref to={to}>{createElement(element, {}, children)}</UISref>
  </UISrefActive>;

// ...

<Link to="somestate" activeClassName="active" element="button">Some link</Link>

from react.

Kukkimonsuta avatar Kukkimonsuta commented on April 17, 2024

That makes sense, however I still think there should be less verbose way to do this. What about just adding optional activeClassName to UISref and let user decide whether can use shorter syntax or whether UISrefActive is required? It feels weird having two ways to do the same thing, but I believe out of the box simplicity is worth it.

Components are fun and do solve the problem if you have a lot of UISrefs with active class name, but you either have to create new for every file or have yet another imported file - which introduces verbosity by itself.

from react.

eddiemonge avatar eddiemonge commented on April 17, 2024

have yet another imported file

Composing the two together like in @elboman's example would actually cut down on imports. Instead of import {UISrefActive, UISref} from '@uirouter/react', it would become import Link from './my-components.

adding optional activeClassName to UIS

This would make the library more complex. Adds more code and logic and also makes implementation more complex. What happens when a user has both UISrefActive and adds the optional activeClassName?

Marking this as closed since it is both old and alternate solutions have been presented.

from react.

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.