Skip to content

Commit 5d3e390

Browse files
authored
Merge pull request #171 from mariohmol/fix/search-scroll-tree-mode-issue-76
fix: auto-scroll to search results in tree/view mode
2 parents f93bd1e + fd6abc8 commit 5d3e390

5 files changed

Lines changed: 55 additions & 29 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ $ npm install --save jsoneditor ang-jsoneditor
2222
Example:
2323

2424
```html
25-
<json-editor [options]="editorOptions" [data]="data" (change)="getData($event)"></json-editor>
25+
<json-editor style="height: 500px;" [options]="editorOptions" [data]="data" (change)="getData($event)"></json-editor>
2626
```
2727

28+
> **Important:** `<json-editor>` requires an explicit height for tree/view/form modes to enable search scrolling and proper layout. Set it directly on the element or via a CSS class. Without a height, the editor expands to fit its content and the built-in search will not auto-scroll to results.
29+
2830
## Usage
2931

3032
### Configuration

projects/ang-jsoneditor/src/lib/jsoneditor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { IError, JsonEditorMode, JsonEditorOptions, JsonEditorTreeNode } from '.
2323
// eslint-disable-next-line @angular-eslint/component-selector
2424
selector: 'json-editor',
2525
template: `<div [id]="id" #jsonEditorContainer></div>`,
26+
styles: [`:host { display: block; } :host > div { height: 100%; }`],
2627
providers: [
2728
{
2829
provide: NG_VALUE_ACCESSOR,

src/app/demo/demo.component.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
json-editor>div {height: 100%;}

src/app/demo/demo.component.html

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,23 @@ <h3>Force Language to {{editorOptions.language}}</h3>
2626
}
2727

2828
<h3>Example with (change)</h3>
29-
<div style="height:600px;">
30-
<json-editor [options]="editorOptions" (change)="changeLog($event)" [data]="data" #editor></json-editor>
31-
<app-show [data]="showData"></app-show>
32-
</div>
29+
<json-editor style="height:600px;" [options]="editorOptions" (change)="changeLog($event)" [data]="data" #editor></json-editor>
30+
<app-show [data]="showData"></app-show>
3331

3432

3533

3634
<h3>Using options and data variable </h3>
3735

38-
<div style="height:300px;">
39-
<form [formGroup]="form" (submit)="submit()">
40-
<json-editor [options]="editorOptions2" formControlName="myinput" #editorTwo></json-editor>
41-
@if (formData) {
42-
<div>
43-
<h4>Form submitted</h4>
44-
{{ formData }}
45-
</div>
46-
}
47-
<button>Submit</button>
48-
</form>
49-
</div>
36+
<form [formGroup]="form" (submit)="submit()">
37+
<json-editor style="height:300px;" [options]="editorOptions2" formControlName="myinput" #editorTwo></json-editor>
38+
@if (formData) {
39+
<div>
40+
<h4>Form submitted</h4>
41+
{{ formData }}
42+
</div>
43+
}
44+
<button>Submit</button>
45+
</form>
5046

5147

5248
<h2>Multi json in a loop</h2>

src/app/demo/demo.ts

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,48 @@ export class Demo implements OnInit {
7474
ngOnInit() {
7575
this.showData = this.data = {
7676
randomNumber: 2,
77+
description: 'Search for "pilot" to test auto-scroll. It is near the bottom of the list.',
78+
manufacturers: [
79+
{ id: 'toyota', country: 'Japan', founded: 1937, employees: 370870 },
80+
{ id: 'ford', country: 'USA', founded: 1903, employees: 186000 },
81+
{ id: 'bmw', country: 'Germany', founded: 1916, employees: 118909 },
82+
{ id: 'mercedes', country: 'Germany', founded: 1926, employees: 172425 },
83+
{ id: 'volkswagen', country: 'Germany', founded: 1937, employees: 672800 },
84+
{ id: 'hyundai', country: 'South Korea', founded: 1967, employees: 75000 },
85+
{ id: 'nissan', country: 'Japan', founded: 1933, employees: 133580 },
86+
{ id: 'chevrolet', country: 'USA', founded: 1911, employees: 155000 },
87+
{ id: 'subaru', country: 'Japan', founded: 1953, employees: 15000 },
88+
{ id: 'mazda', country: 'Japan', founded: 1920, employees: 48000 }
89+
],
7790
products: [
7891
{
7992
name: 'car',
80-
product:
81-
[
82-
{
83-
name: 'honda',
84-
model: [
85-
{ id: 'civic', name: 'civic' },
86-
{ id: 'accord', name: 'accord' }, { id: 'crv', name: 'crv' },
87-
{ id: 'pilot', name: 'pilot' }, { id: 'odyssey', name: 'odyssey' }
88-
]
89-
}
90-
]
93+
product: [
94+
{
95+
name: 'honda',
96+
model: [
97+
{ id: 'civic', name: 'civic', year: 2020, price: 21550 },
98+
{ id: 'accord', name: 'accord', year: 2021, price: 25970 },
99+
{ id: 'crv', name: 'crv', year: 2022, price: 28410 },
100+
{ id: 'hrv', name: 'hrv', year: 2022, price: 23650 },
101+
{ id: 'fit', name: 'fit', year: 2020, price: 16190 },
102+
{ id: 'ridgeline', name: 'ridgeline', year: 2022, price: 36490 },
103+
{ id: 'passport', name: 'passport', year: 2022, price: 37050 },
104+
{ id: 'pilot', name: 'pilot', year: 2022, price: 38170 },
105+
{ id: 'odyssey', name: 'odyssey', year: 2022, price: 32490 }
106+
]
107+
},
108+
{
109+
name: 'toyota',
110+
model: [
111+
{ id: 'camry', name: 'camry', year: 2022, price: 25945 },
112+
{ id: 'corolla', name: 'corolla', year: 2022, price: 20075 },
113+
{ id: 'rav4', name: 'rav4', year: 2022, price: 27575 },
114+
{ id: 'highlander', name: 'highlander', year: 2022, price: 35810 },
115+
{ id: 'tacoma', name: 'tacoma', year: 2022, price: 27450 }
116+
]
117+
}
118+
]
91119
}
92120
]
93121
};

0 commit comments

Comments
 (0)