Skip to content

Commit

Permalink
fix(Button): support re patching prefix after undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
THoj13 committed Nov 13, 2023
1 parent 34438a9 commit 965cc73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default class Button extends Surface {
}

_updatePrefix() {
const prefixString = JSON.stringify(this.prefix);
if (this.prefix) {
let prefixPatch = {
style: {
Expand All @@ -128,16 +129,15 @@ export default class Button extends Surface {
* from something else (ex. a change in mode), only update the styles applied to the
* items in the Prefix (ex. updating the color to the value appropriate to the new mode).
*/
const prefixString = JSON.stringify(this.prefix);
if (prefixString !== this._prevPrefix) {
this._prevPrefix = prefixString;
this._Prefix.items = this._addButtonProps(this.prefix);
} else {
this._updatePrefixStyles();
}
} else {
this._Content.patch({ Prefix: undefined });
}
this._prevPrefix = prefixString;
}

_updatePrefixStyles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ describe('Button', () => {
testRenderer.forceAllUpdates();
expect(button._Prefix.items.length).toEqual(button.prefix.length);
});

it('should render a new preix row when a prefix is toggled between undefined and defined', () => {
expect(button._Prefix).toBeUndefined();

button.prefix = [{ type: Icon }];
testRenderer.forceAllUpdates();
expect(button._Prefix.items.length).toEqual(button.prefix.length);

button.prefix = undefined;
testRenderer.forceAllUpdates();
expect(button._Prefix).toBeUndefined();

button.prefix = [{ type: Icon }];
testRenderer.forceAllUpdates();
expect(button._Prefix.items.length).toEqual(button.prefix.length);
});
});

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

0 comments on commit 965cc73

Please sign in to comment.