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: do not override theme attribute set on slotted buttons #7215

Merged
merged 1 commit into from
Mar 15, 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
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
Loading