Skip to content

Commit

Permalink
fix: do not override theme attribute set on slotted buttons (#7215) (#…
Browse files Browse the repository at this point in the history
…7218)

Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
  • Loading branch information
vaadin-bot and web-padawan authored Mar 15, 2024
1 parent b6f98ee commit e400872
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/crud/src/vaadin-crud-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export class ButtonSlotController extends SlotController {
this.defaultNode = node;
}

if (node === this.defaultNode) {
// Respect default theme attribute set by the Flow counterpart
if (node === this.defaultNode && !node.hasAttribute('theme')) {
node.setAttribute('theme', this.theme);
}

Expand Down
76 changes: 76 additions & 0 deletions packages/crud/test/crud-buttons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,25 @@ describe('crud buttons', () => {

expect(button.textContent).to.equal('Add user');
});

it('should set theme attribute of the new item button when marked as a default', async () => {
button._isDefault = true;

crud.appendChild(button);
await nextRender();

expect(button.getAttribute('theme')).to.equal('primary');
});

it('should not change theme attribute of the new item button when marked as a default', async () => {
button._isDefault = true;
button.setAttribute('theme', 'primary success');

crud.appendChild(button);
await nextRender();

expect(button.getAttribute('theme')).to.equal('primary success');
});
});

describe('delete', () => {
Expand Down Expand Up @@ -774,6 +793,25 @@ describe('crud buttons', () => {

expect(button.textContent).to.equal('Drop user');
});

it('should set theme attribute of the delete button when marked as a default', async () => {
button._isDefault = true;

crud.appendChild(button);
await nextRender();

expect(button.getAttribute('theme')).to.equal('tertiary error');
});

it('should not change theme attribute of the delete button when marked as a default', async () => {
button._isDefault = true;
button.setAttribute('theme', 'tertiary contrast');

crud.appendChild(button);
await nextRender();

expect(button.getAttribute('theme')).to.equal('tertiary contrast');
});
});

describe('save', () => {
Expand Down Expand Up @@ -810,6 +848,25 @@ describe('crud buttons', () => {

expect(button.textContent).to.equal('Save user');
});

it('should set theme attribute of the save button when marked as a default', async () => {
button._isDefault = true;

crud.appendChild(button);
await nextRender();

expect(button.getAttribute('theme')).to.equal('primary');
});

it('should not change theme attribute of the save button when marked as a default', async () => {
button._isDefault = true;
button.setAttribute('theme', 'primary contrast');

crud.appendChild(button);
await nextRender();

expect(button.getAttribute('theme')).to.equal('primary contrast');
});
});

describe('cancel', () => {
Expand Down Expand Up @@ -846,6 +903,25 @@ describe('crud buttons', () => {

expect(button.textContent).to.equal('Discard');
});

it('should set theme attribute of the cancel button when marked as a default', async () => {
button._isDefault = true;

crud.appendChild(button);
await nextRender();

expect(button.getAttribute('theme')).to.equal('tertiary');
});

it('should not change theme attribute of the cancel button when marked as a default', async () => {
button._isDefault = true;
button.setAttribute('theme', 'tertiary contrast');

crud.appendChild(button);
await nextRender();

expect(button.getAttribute('theme')).to.equal('tertiary contrast');
});
});
});

Expand Down

0 comments on commit e400872

Please sign in to comment.