Skip to content
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

fix: teleport CRUD form to overlay if some buttons are not set (#8372) (CP: 24.5) #8380

Merged
merged 1 commit into from
Dec 20, 2024
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
5 changes: 3 additions & 2 deletions packages/crud/src/vaadin-crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,14 +820,15 @@ class Crud extends ControllerMixin(ElementMixin(ThemableMixin(PolymerElement)))

/** @private */
__moveChildNodes(target) {
const nodes = [this._headerNode, this._form, this._saveButton, this._cancelButton, this._deleteButton];
const nodes = [this._headerNode, this._form];
const buttons = [this._saveButton, this._cancelButton, this._deleteButton].filter(Boolean);
if (!nodes.every((node) => node instanceof HTMLElement)) {
return;
}

// Teleport header node, form, and the buttons to corresponding slots.
// NOTE: order in which buttons are moved matches the order of slots.
nodes.forEach((node) => {
[...nodes, ...buttons].forEach((node) => {
target.appendChild(node);
});

Expand Down
9 changes: 9 additions & 0 deletions packages/crud/test/crud-buttons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ describe('crud buttons', () => {
beforeEach(async () => {
crud = document.createElement('vaadin-crud');
crud._noDefaultButtons = true;
crud.items = [{ foo: 'bar' }];
document.body.appendChild(crud);
await nextRender();
});
Expand All @@ -954,6 +955,14 @@ describe('crud buttons', () => {
it('should not create default delete-button', () => {
expect(crud.querySelector('[slot="delete-button"]')).to.be.null;
});

it('should teleport form and header when no default buttons set', async () => {
crud.editedItem = { foo: 'baz' };
await nextRender();
const overlay = crud.$.dialog.$.overlay;
expect(crud._form.parentElement).to.equal(overlay);
expect(crud._headerNode.parentElement).to.equal(overlay);
});
});

describe('dataProvider', () => {
Expand Down