Skip to content
Open
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
6 changes: 4 additions & 2 deletions blocks/canvas/ew-block-toolbar/ew-block-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ class EwBlockToolbar extends LitElement {
const picker = this._picker;
if (!picker) return;
const current = this._currentVariant ?? '';
if (current === '' || (this._variantOptions || []).includes(current)) {
picker.value = current;
const match = (this._variantOptions || [])
.find((v) => normalizeBlockName(v) === normalizeBlockName(current));
if (match) {
picker.value = match;
picker.labelOverride = '';
} else {
picker.value = '';
Expand Down
30 changes: 30 additions & 0 deletions test/unit/blocks/canvas/ew-block-toolbar/ew-block-toolbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ describe('ew-block-toolbar', () => {
expect(toolbar.shadowRoot.querySelector('nx-picker').value).to.equal('highlight');
});

it('selects "No variant" when there is no current variant', async () => {
toolbar.show('cards');
toolbar._variantOptions = ['wide', 'blue'];
await toolbar.updateComplete;

const picker = toolbar.shadowRoot.querySelector('nx-picker');
expect(picker.value).to.equal('');
expect(picker.labelOverride).to.equal('');
});

it('matches the current variant case-insensitively', async () => {
toolbar.show('cards', 'wide');
toolbar._variantOptions = ['Wide'];
await toolbar.updateComplete;

const picker = toolbar.shadowRoot.querySelector('nx-picker');
expect(picker.value).to.equal('Wide');
expect(picker.labelOverride).to.equal('');
});

it('matches the current variant ignoring spacing differences', async () => {
toolbar.show('cards', 'two up');
toolbar._variantOptions = ['Two-Up'];
await toolbar.updateComplete;

const picker = toolbar.shadowRoot.querySelector('nx-picker');
expect(picker.value).to.equal('Two-Up');
expect(picker.labelOverride).to.equal('');
});

function editBtn() {
return toolbar.shadowRoot.querySelector('.block-edit');
}
Expand Down
Loading