Skip to content

Commit 12b87de

Browse files
authored
Merge branch 'jsonforms2' into jsonforms2_reference_refactor
2 parents 524596e + cc78dec commit 12b87de

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/renderers/additional/tree-renderer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,20 @@ export class TreeMasterDetailRenderer extends Renderer implements DataChangeList
139139

140140
this.appendChild(div);
141141
this.dialog = document.createElement('dialog');
142+
this.dialog.classList.add('jsf-treeMasterDetail-dialog');
142143
const title = document.createElement('label');
143144
title.innerText = 'Select the Item to create:';
145+
title.classList.add('jsf-treeMasterDetail-dialog-title');
144146
this.dialog.appendChild(title);
145147
const dialogContent = document.createElement('div');
146148
dialogContent.classList.add('content');
149+
dialogContent.classList.add('jsf-treeMasterDetail-dialog-content');
147150
this.dialog.appendChild(dialogContent);
148151
const dialogClose = document.createElement('button');
149152
dialogClose.innerText = 'Close';
150153
dialogClose.onclick = () => this.dialog.close();
154+
JsonForms.stylingRegistry.addStyle(dialogClose, 'button');
155+
dialogClose.classList.add('jsf-treeMasterDetail-dialog-button');
151156
this.dialog.appendChild(dialogClose);
152157
this.appendChild(this.dialog);
153158
this.renderFull();
@@ -394,6 +399,8 @@ export class TreeMasterDetailRenderer extends Renderer implements DataChangeList
394399
JsonForms.schemaService.getContainmentProperties(schema).forEach(property => {
395400
const button = document.createElement('button');
396401
button.innerText = property.label;
402+
button.classList.add('jsf-treeMasterDetail-dialog-createbutton');
403+
JsonForms.stylingRegistry.addStyle(button, 'button');
397404
button.onclick = () => {
398405
const newData = {};
399406
// initialize new data with default values from schema
@@ -410,6 +417,8 @@ export class TreeMasterDetailRenderer extends Renderer implements DataChangeList
410417
content.appendChild(button);
411418
});
412419
this.dialog.showModal();
420+
// Focus the close dialog's button
421+
this.dialog.getElementsByClassName('jsf-treeMasterDetail-dialog-button')[0].focus();
413422
};
414423
spanAdd.textContent = '\u2795';
415424
span.appendChild(spanAdd);

test/renderers/treemasterdetail.control.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ test('TreeMasterDetailRenderer static object', t => {
173173
scope: { $ref: '#' }
174174
};
175175
JsonForms.schema = schema;
176+
JsonForms.stylingRegistry.register('button', ['buttonCSS']);
176177
const renderer: TreeMasterDetailRenderer = new TreeMasterDetailRenderer();
177178
const data = {name: 'Foo', children: [{name: 'Bar'}]};
178179
renderer.setDataService(new DataService(data));
@@ -234,14 +235,18 @@ test('TreeMasterDetailRenderer static object', t => {
234235
// dialog
235236
const dialog = result.children[2];
236237
t.is(dialog.children.length, 3);
238+
t.is(dialog.className, 'jsf-treeMasterDetail-dialog');
237239
const dialogLabel = dialog.children[0] as HTMLLabelElement;
238240
t.is(dialogLabel.tagName, 'LABEL');
239241
t.is(dialogLabel.innerText, 'Select the Item to create:');
242+
t.is(dialogLabel.className, 'jsf-treeMasterDetail-dialog-title');
240243
const dialogContent = dialog.children[1] as HTMLDivElement;
241244
t.is(dialogContent.tagName, 'DIV');
242-
t.is(dialogContent.className, 'content');
245+
t.is(dialogContent.className, 'content jsf-treeMasterDetail-dialog-content');
243246
const dialogClose = dialog.children[2] as HTMLButtonElement;
244247
t.is(dialogClose.tagName, 'BUTTON');
248+
t.true(dialogClose.classList.contains('jsf-treeMasterDetail-dialog-button'));
249+
t.true(dialogClose.classList.contains('buttonCSS'));
245250
t.is(dialogClose.innerText, 'Close');
246251
});
247252

@@ -285,6 +290,7 @@ test('TreeMasterDetailRenderer static array', t => {
285290
}
286291
};
287292
const renderer: TreeMasterDetailRenderer = new TreeMasterDetailRenderer();
293+
JsonForms.stylingRegistry.register('button', ['buttonCSS']);
288294
const data = [{name: 'Foo', children: [{name: 'Bar'}]}];
289295
renderer.setDataService(new DataService(data));
290296
renderer.setDataSchema(schema);
@@ -355,14 +361,18 @@ test('TreeMasterDetailRenderer static array', t => {
355361
// dialog
356362
const dialog = result.children[2];
357363
t.is(dialog.children.length, 3);
364+
t.is(dialog.className, 'jsf-treeMasterDetail-dialog');
358365
const dialogLabel = dialog.children[0] as HTMLLabelElement;
359366
t.is(dialogLabel.tagName, 'LABEL');
360367
t.is(dialogLabel.innerText, 'Select the Item to create:');
368+
t.is(dialogLabel.className, 'jsf-treeMasterDetail-dialog-title');
361369
const dialogContent = dialog.children[1] as HTMLDivElement;
362370
t.is(dialogContent.tagName, 'DIV');
363-
t.is(dialogContent.className, 'content');
371+
t.is(dialogContent.className, 'content jsf-treeMasterDetail-dialog-content');
364372
const dialogClose = dialog.children[2] as HTMLButtonElement;
365373
t.is(dialogClose.tagName, 'BUTTON');
374+
t.true(dialogClose.classList.contains('jsf-treeMasterDetail-dialog-button'));
375+
t.true(dialogClose.classList.contains('buttonCSS'));
366376
t.is(dialogClose.innerText, 'Close');
367377
});
368378

@@ -385,6 +395,7 @@ test('TreeMasterDetailRenderer static array not root', t => {
385395
};
386396
JsonForms.schema = schema;
387397
const renderer: TreeMasterDetailRenderer = new TreeMasterDetailRenderer();
398+
JsonForms.stylingRegistry.register('button', ['buttonCSS']);
388399
const data = {name: 'Foo', children: [{name: 'Bar'}]};
389400
const uiSchema: MasterDetailLayout = {
390401
type: 'MasterDetailLayout',
@@ -439,14 +450,18 @@ test('TreeMasterDetailRenderer static array not root', t => {
439450
// dialog
440451
const dialog = result.children[2];
441452
t.is(dialog.children.length, 3);
453+
t.is(dialog.className, 'jsf-treeMasterDetail-dialog');
442454
const dialogLabel = dialog.children[0] as HTMLLabelElement;
443455
t.is(dialogLabel.tagName, 'LABEL');
444456
t.is(dialogLabel.innerText, 'Select the Item to create:');
457+
t.is(dialogLabel.className, 'jsf-treeMasterDetail-dialog-title');
445458
const dialogContent = dialog.children[1] as HTMLDivElement;
446459
t.is(dialogContent.tagName, 'DIV');
447-
t.is(dialogContent.className, 'content');
460+
t.is(dialogContent.className, 'content jsf-treeMasterDetail-dialog-content');
448461
const dialogClose = dialog.children[2] as HTMLButtonElement;
449462
t.is(dialogClose.tagName, 'BUTTON');
463+
t.true(dialogClose.classList.contains('jsf-treeMasterDetail-dialog-button'));
464+
t.true(dialogClose.classList.contains('buttonCSS'));
450465
t.is(dialogClose.innerText, 'Close');
451466
});
452467

0 commit comments

Comments
 (0)