Skip to content

syncing commit from monorepo. PR: 212, Title: FIO-10089: Default opened group in sidebar #6182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/calm-steaks-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@formio/js": patch
---

change behaviour for default opened groups in sidebar
11 changes: 10 additions & 1 deletion src/WebformBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@ export default class WebformBuilder extends Component {
this.groupOrder = this.groupOrder
.filter(group => group && !group.ignore)
.sort((a, b) => a.weight - b.weight)
.map(group => group.key);

const defaultOpenedGroup = this.groupOrder.find(x => x.key !== 'basic' && x.default);
if (defaultOpenedGroup) {
this.groupOrder.forEach(x => {
if ('default' in x && x.key !== defaultOpenedGroup.key) {
x.default = false;
}
});
}
this.groupOrder = this.groupOrder.map(group => group.key);

for (const type in Components.components) {
const component = Components.components[type];
Expand Down
36 changes: 36 additions & 0 deletions test/unit/WebformBuilder.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import formWithFormController from '../forms/formWithFormController';
import simpleWebform from '../forms/simpleWebform';
import formWithNumericKeys from '../forms/formWithNumericKeys';
import testUniqueApiKey from '../forms/testUniqueApiKey';
import FormBuilder from '../../src/FormBuilder';

global.requestAnimationFrame = (cb) => cb();
global.cancelAnimationFrame = () => {};
Expand All @@ -27,6 +28,41 @@ describe('WebformBuilder tests', function() {
done();
});

it("Should open only one default opened group at a time", async () => {
const builderOptions = {
some_group1: {
title: "Components group 1",
weight: 10,
default: true,
components: {
content: true,
}
},
some_group2: {
title: "Components group 2",
weight: 9,
default: true,
components: {
captcha: true
}
}
}
const builder = new FormBuilder(document.createElement('div'), { display: 'form', components: [] }, { builder: builderOptions });
await builder.ready;
const sidebarContainer = builder.element.querySelector('[ref="sidebar-groups"]');
const groupsCollapse = [...sidebarContainer.querySelectorAll('[ref="sidebar-group"]')];
// Should be opened only one group with default = true. As we get sort ascending (by weight field) the "Components group 2" will be visible
groupsCollapse.forEach(x => {
const id = x.getAttribute("id");
if (id.includes("some_group2")) {
assert.equal(x.classList.contains('show'), true);
}
else {
assert.equal(x.classList.contains('show'), false);
}
})
});

it("Should not show errors with default array values", (done) => {
const builder = Harness.getBuilder();
builder
Expand Down
Loading