.isActive() and nested nodes
See original GitHub issueCurrently .isActive
checks to see if the node is active at any point in a nested tree of nodes, this is slightly problematic with nested list of different types. So ,for example, I have a toolbar with both ul
and ol
buttons and use isActive
to set the active state of the button, if you nest a ul within an ol both are technically active and so both buttons show as active.
Would it be possible to have a depth
argument or ‘isActiveTop()’ so that we can check if only is the top level node matches?
Additionally isActive('paragraph')
returns true with most other node types as they almost all nest a paragraph within them (list, tables, blockquotes ect.), could there be a exclusive
argument or a isActiveOnly()
option?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Running hql query for nested element returns "unexpected ...
I'm using grails 2.3.4; I have no problem accessing the information p.owner.contract.isActive in my grails code; A product always has an owner ...
Read more >Node | Sceneform (1.15.0) - Google Developers
Nested Classes; Public Constructors; Public Methods; Protected Methods ... Returns true if the node is active. ... public final boolean isActive ().
Read more >NavLink - React Router: Declarative Routing for React.js
A function to add extra logic for determining whether the link is active. This should be used if you want to do more...
Read more >Class - No Magic Documentation
Returns the value of the 'Nested Classifier' containment reference list. java.util. ... boolean, hasNestedClassifier() ... boolean, isActive().
Read more >Migrating to React Router v6: A complete guide
For nested routes, developers had to find the entire route because there ... In React Router v5, we use useHistory() for handling navigation ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Having put some more thought into this I have made a new helper that solves this problem, a depth arg would not solve it as its hard to know how ‘deep’ to test and its ambiguous how that would work on a multi node selection.
This helper,
lastActiveNodes
, finds the last (furthest from the root document) matching types in your selection (ignoring nesting), you can give it either a list of args similar toisActive
or a group name, calling it like below. It will return a list of node type names that are the last ones active in the selection, if the selection is ‘empty’ (just the cursor) the returned list will only have at most one name. This lets you build a UI for lists that works the same as most word processors.If you are checking for arguments of the same node type (for example for headings) you can provide an additional
key
for each type that will be returned if it matches.In action:
https://user-images.githubusercontent.com/31130/107784283-28391c80-6d43-11eb-96f6-d9bd9a77198b.mov
I think the inverse, a
firstActiveNodes
, will solve theisActive('paragraph')
use case and so that’s on my todo list…The code:
Currently, I don’t have plans to add this to the core. But thanks again for the code. I’m sure it will help some people 👍