Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-json-treeview",
"version": "19.1.0",
"version": "19.2.0",
"license": "Apache-2.0",
"author": {
"name": "Michael J Doyle",
Expand Down
1 change: 1 addition & 0 deletions projects/demo/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h3>Clickable Nodes</h3>
<ngx-json-treeview
[json]="json"
[expanded]="false"
[isClickableValue]="isClickableValue"
[enableClickableValues]="true"
(onValueClick)="onValueClick($event)" />
</div>
Expand Down
4 changes: 4 additions & 0 deletions projects/demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export class AppComponent {
},
};

isClickableValue(segment: Segment) {
return ['object', 'array', 'string'].includes(segment.type ?? '');
}

onValueClick(segment: Segment) {
this.currentSegment.set(segment);
}
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-json-treeview/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-json-treeview",
"version": "19.1.0",
"version": "19.2.0",
"license": "Apache-2.0",
"author": {
"name": "Michael J Doyle",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
@if (!expandable || !segment.expanded) {
<span
[class]="expandable ? 'segment-label' : 'segment-value'"
[class.clickable]="enableClickableValues()"
(click)="onValueClickHandler(segment)">
[class.clickable]="
enableClickableValues() && isClickableValue()(segment)
"
(click)="
isClickableValue()(segment)
? onValueClickHandler(segment)
: undefined
">
{{ segment.description }}
</span>
} @else if (expandable && segment.expanded) {
Expand All @@ -39,6 +45,7 @@
[json]="segment.value"
[expanded]="expanded()"
[depth]="depth()"
[isClickableValue]="isClickableValue()"
[enableClickableValues]="enableClickableValues()"
[_parent]="segment"
[_currentDepth]="_currentDepth() + 1"
Expand Down
19 changes: 19 additions & 0 deletions projects/ngx-json-treeview/src/lib/ngx-json-treeview.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface Segment {
path: string;
}

export type IsClickableValueFn = (segment: Segment) => boolean;

/**
* Renders JSON data in an expandable and collapsible tree structure.
* Allows users to navigate complex data hierarchies visually.
Expand Down Expand Up @@ -73,6 +75,23 @@ export class NgxJsonTreeviewComponent {
*/
enableClickableValues = input<boolean>(false);

/**
* A function that determines if a specific value node should be considered
* clickable. This provides more granular control than the global
* `enableClickableValues` flag.
*
* The function receives the `Segment` object and should return `true` if the
* value is clickable, `false` otherwise. This check is only performed if
* `enableClickableValues` is also `true`.
*
* @param segment - The segment being evaluated.
* @returns `true` if the segment's value should be clickable, `false`
* otherwise.
* @default () => true - By default, all values are considered clickable if
* `enableClickableValues` is true.
*/
isClickableValue = input<IsClickableValueFn>(() => true);

/**
* If `enableClickableValues` is set to `true`, emits a `Segment` object when
* a value node is clicked. The emitted `Segment` contains details about the
Expand Down