Code Monkey home page Code Monkey logo

Comments (9)

mrchief avatar mrchief commented on May 25, 2024 3

Yeah it gets messy with an HOC.

Looking at your PR, and this discussion, I think the interface should be like this:

  • Introduce a new property at the node level - say disabled?
  • If a node is disabled, disable the checkbox and emit disabled classname.

This has the following benefits:

  • Keeps it generic enough for single root and multi root trees.
  • Allows you to have greater flexibility in disabling nodes (goes beyond levels).
  • Emitting the class lets you customize the presentational aspect - one can choose to hide or show differently based on their specific business needs.

Thoughts?

from react-dropdown-tree-select.

mrchief avatar mrchief commented on May 25, 2024

That's an interesting use case.

On one hand, I think it'd be nice to have a node level prop that disables the node (and may be its children too? I'm thinking similar to node.checked...). On the other hand, I'd like to keep the core plugin simple and light.

Would you mind sharing some further details about how you plan to implement this (HOC and/or natively)?

from react-dropdown-tree-select.

Gregcop1 avatar Gregcop1 commented on May 25, 2024

Our needs is to disable selection for specific level. For example, it's not possible to select first and second level.
With a HOC, I think I can use onChange event to catch selection and stop propagation or revert the change (I have watch yet if you fire event before or after change)
Natively, it could be more powerful cause we can remove checkbox for those levels and not firing the onChange event at all.
I start dev on our project (with a HOC), keep me inform if you want me to include this in the lib.

from react-dropdown-tree-select.

Gregcop1 avatar Gregcop1 commented on May 25, 2024

I tried with an HOC, I can prevent tag creation and revert the click for the selected level but not for it's children :/
One solution may be to add more events to native component (onPreChange for ex)
Otherwise if you want to handle it natively, I pushed you a small PR (#50 )

from react-dropdown-tree-select.

mrchief avatar mrchief commented on May 25, 2024

You're welcome to take a stab at it (your PR is close enough already) or else I can get to it in few days.

from react-dropdown-tree-select.

Gregcop1 avatar Gregcop1 commented on May 25, 2024

Ok, I will work on it soon.

from react-dropdown-tree-select.

benwiggins avatar benwiggins commented on May 25, 2024

I've been using some pretty hacky CSS child selectors to achieve something similar by setting pointer-events: none on labels and display:none on checkboxes. Looking forward to an 'official' disabled class :)

from react-dropdown-tree-select.

Gregcop1 avatar Gregcop1 commented on May 25, 2024

You can check progress on #50

from react-dropdown-tree-select.

mrchief avatar mrchief commented on May 25, 2024

This is available with v1.4.0

from react-dropdown-tree-select.

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.