Skip to content

Commit a8f45f4

Browse files
authored
refactor!: remove ID attribute from slotted buttons (#4960)
1 parent 879a5f2 commit a8f45f4

2 files changed

Lines changed: 17 additions & 29 deletions

File tree

‎packages/crud/src/vaadin-crud.js‎

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ import { MediaQueryController } from '@vaadin/component-base/src/media-query-con
1818
import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
1919
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
2020

21+
/**
22+
* @private
23+
* A to initialize slotted button.
24+
*/
25+
class ButtonSlotController extends SlotController {
26+
constructor(host, type, theme) {
27+
super(host, `${type}-button`, 'vaadin-button', {
28+
initializer: (button) => {
29+
button.setAttribute('theme', theme);
30+
},
31+
});
32+
}
33+
}
34+
2135
/**
2236
* `<vaadin-crud>` is a Web Component for [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operations.
2337
*
@@ -646,32 +660,9 @@ class Crud extends ControllerMixin(ElementMixin(ThemableMixin(PolymerElement)))
646660
this.addController(new SlotController(this, 'form', 'vaadin-crud-form'));
647661

648662
// NOTE: order in which buttons are added should match the order of slots in template
649-
this.addController(
650-
new SlotController(this, 'save-button', 'vaadin-button', {
651-
initializer: (button) => {
652-
button.id = 'save';
653-
button.setAttribute('theme', 'primary');
654-
},
655-
}),
656-
);
657-
658-
this.addController(
659-
new SlotController(this, 'cancel-button', 'vaadin-button', {
660-
initializer: (button) => {
661-
button.id = 'cancel';
662-
button.setAttribute('theme', 'tertiary');
663-
},
664-
}),
665-
);
666-
667-
this.addController(
668-
new SlotController(this, 'delete-button', 'vaadin-button', {
669-
initializer: (button) => {
670-
button.id = 'delete';
671-
button.setAttribute('theme', 'tertiary error');
672-
},
673-
}),
674-
);
663+
this.addController(new ButtonSlotController(this, 'save', 'primary'));
664+
this.addController(new ButtonSlotController(this, 'cancel', 'tertiary'));
665+
this.addController(new ButtonSlotController(this, 'delete', 'tertiary error'));
675666

676667
this.addController(
677668
new MediaQueryController(this._fullscreenMediaQuery, (matches) => {

‎packages/crud/test/dom/__snapshots__/crud.test.snap.js‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ snapshots["vaadin-crud host default"] =
144144
<vaadin-button
145145
aria-disabled="true"
146146
disabled=""
147-
id="save"
148147
role="button"
149148
slot="save-button"
150149
tabindex="-1"
@@ -153,7 +152,6 @@ snapshots["vaadin-crud host default"] =
153152
Save
154153
</vaadin-button>
155154
<vaadin-button
156-
id="cancel"
157155
role="button"
158156
slot="cancel-button"
159157
tabindex="0"
@@ -163,7 +161,6 @@ snapshots["vaadin-crud host default"] =
163161
</vaadin-button>
164162
<vaadin-button
165163
hidden=""
166-
id="delete"
167164
role="button"
168165
slot="delete-button"
169166
tabindex="0"

0 commit comments

Comments
 (0)