Skip to content

Commit 96a3d89

Browse files
authored
feat: deprecate render() for menu-bar (#2154)
1 parent 9e75b34 commit 96a3d89

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

‎packages/vaadin-menu-bar/src/vaadin-menu-bar-buttons-mixin.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,18 @@ export const ButtonsMixin = (superClass) =>
136136
/**
137137
* Call this method after updating menu bar `items` dynamically, including changing
138138
* any property on the item object corresponding to one of the menu bar buttons.
139+
*
140+
* @deprecated Since Vaadin 21, `render()` is deprecated. The `items` value is immutable. Please replace it with a new value instead of mutating in place.
139141
*/
140142
render() {
143+
console.warn(
144+
'WARNING: Since Vaadin 21, render() is deprecated. The items value is immutable. Please replace it with a new value instead of mutating in place.'
145+
);
146+
141147
if (!this.shadowRoot) {
142148
return;
143149
}
150+
144151
this.__renderButtons(this.items);
145152
}
146153

‎packages/vaadin-menu-bar/test/menu-bar.test.js‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ describe('root menu layout', () => {
8080
expect(() => document.createElement('vaadin-menu-bar').render()).to.not.throw(Error);
8181
});
8282

83+
it('should render buttons when calling deprecated render()', () => {
84+
const stub = sinon.stub(menu, '__renderButtons');
85+
menu.render();
86+
stub.restore();
87+
88+
expect(stub.calledOnce).to.be.true;
89+
});
90+
91+
it('should warn when calling deprecated render()', () => {
92+
const stub = sinon.stub(console, 'warn');
93+
menu.render();
94+
stub.restore();
95+
96+
expect(stub.calledOnce).to.be.true;
97+
expect(stub.args[0][0]).to.equal(
98+
'WARNING: Since Vaadin 21, render() is deprecated. The items value is immutable. Please replace it with a new value instead of mutating in place.'
99+
);
100+
});
101+
83102
describe('keyboard navigation', () => {
84103
describe('default mode', () => {
85104
it('should move focus to next button on "arrow-right" keydown', () => {
@@ -107,8 +126,8 @@ describe('root menu layout', () => {
107126
});
108127

109128
it('should move focus to second button if first is disabled on "home" keydown', () => {
110-
menu.set('items.0.disabled', true);
111-
menu.render();
129+
menu.items[0].disabled = true;
130+
menu.items = [...menu.items];
112131
buttons = menu._buttons;
113132
buttons[3].focus();
114133
const spy = sinon.spy(buttons[1], 'focus');
@@ -126,8 +145,8 @@ describe('root menu layout', () => {
126145
});
127146

128147
it('should move focus to the closest enabled button if last is disabled on "end" keydown', () => {
129-
menu.set('items.3.disabled', true);
130-
menu.render();
148+
menu.items[3].disabled = true;
149+
menu.items = [...menu.items];
131150
buttons = menu._buttons;
132151
buttons[0].focus();
133152
const spy = sinon.spy(buttons[1], 'focus');

‎wtr-utils.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const HIDDEN_WARNINGS = [
88
'The <vaadin-grid> needs the total number of items in order to display rows. Set the total number of items to the `size` property, or provide the total number of items in the second argument of the `dataProvider`’s `callback` call.',
99
'PositionMixin is not considered stable and might change any time',
1010
'WARNING: Since Vaadin 21, update() is deprecated. Please use updateConfiguration() instead.',
11+
'WARNING: Since Vaadin 21, render() is deprecated. The items value is immutable. Please replace it with a new value instead of mutating in place.',
1112
/^WARNING: <template> inside <[^>]+> is deprecated. Use a renderer function instead/
1213
];
1314

0 commit comments

Comments
 (0)