Skip to content

Commit

Permalink
Merge pull request #127 from Neovici/feature/no-resize
Browse files Browse the repository at this point in the history
fix: add no-resize option in cosmoz-tabs
  • Loading branch information
Patrik Kullman authored Oct 1, 2020
2 parents efe6e18 + 4b6650e commit 0eef7b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cosmoz-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ const Tabs = host => {
};

customElements.define('cosmoz-tabs', component(Tabs, {
observedAttributes: ['selected', 'hash-param']
observedAttributes: ['selected', 'hash-param', 'no-resize']
}));
4 changes: 3 additions & 1 deletion lib/use-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const useTabSelectedEffect = (host, selectedTab) => {
}

selectedTab.dispatchEvent(new CustomEvent('tab-select', opts));
requestAnimationFrame(() => window.dispatchEvent(new Event('resize')));
if (!host.noResize) {
requestAnimationFrame(() => window.dispatchEvent(new Event('resize')));
}
return () => {
selectedTab.toggleAttribute('is-selected', false);
};
Expand Down
14 changes: 14 additions & 0 deletions test/cosmoz-tabs-basic.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
assert, html, fixture, nextFrame
} from '@open-wc/testing';
import { spy } from 'sinon';

import '../cosmoz-tabs.js';

Expand Down Expand Up @@ -31,6 +32,19 @@ suite('cosmoz-tabs', () => {
assert.equal(tabs.querySelector('[is-selected]').getAttribute('name'), 'tab1');
});

test('does not resize on select', async () => {
tabs.toggleAttribute('no-resize', true);
await nextFrame();

const resizeSpy = spy();
window.addEventListener('resize', resizeSpy);

tabs.selected = 'tab1';
await nextFrame();
window.removeEventListener('resize', resizeSpy);
assert.isTrue(resizeSpy.notCalled);
});

test('contains a tablist with the same number of tabs', () => {
assert.lengthOf(tabs.shadowRoot.querySelectorAll('[role=tab]'), tabs.querySelectorAll('cosmoz-tab').length);
});
Expand Down

0 comments on commit 0eef7b2

Please sign in to comment.