Skip to content

Commit

Permalink
fix: correctly notify selected
Browse files Browse the repository at this point in the history
There was an attempt to fix `selected` notification in #126 but it was incomplete.
This restores original cosmoz-tabs `selected` notification
  • Loading branch information
megheaiulian committed Oct 8, 2020
1 parent 429c607 commit 086ae7d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
9 changes: 4 additions & 5 deletions lib/use-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import {
const useTabSelectedEffect = (host, selectedTab) => {
useEffect(() => {
notifyProperty(host, 'selectedItem', selectedTab);
if (!selectedTab) {
if (selectedTab == null) {
return;
}
if (host.selected == null) {
notifyProperty(host, 'selected', selectedTab.getAttribute('name'));
}
selectedTab.toggleAttribute('is-selected', true);
const opts = {
bubbles: false,
Expand Down Expand Up @@ -47,10 +50,6 @@ const useTabSelectedEffect = (host, selectedTab) => {

useTabSelectedEffect(host, selectedTab);

useEffect(() => {
notifyProperty(host, 'selected', selection);
}, []);

useEffect(() => {
const onTabAlter = e => {
e.stopPropagation();
Expand Down
4 changes: 2 additions & 2 deletions test/cosmoz-tabs-basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ suite('cosmoz-tabs', () => {
});

test('selects an item', async () => {
assert.equal(tabs.selected, undefined);
assert.equal(tabs.selected, 'tab0');
assert.equal(tabs.querySelector('[is-selected]').getAttribute('name'), 'tab0');

tabs.selected = 'tab1';
Expand Down Expand Up @@ -180,7 +180,7 @@ suite('cosmoz-tabs', () => {
hiddenTab.hidden = false;
await nextFrame();

assert.equal(tabs.querySelector('[is-selected]'), hiddenTab);
assert.equal(tabs.querySelector('[is-selected]').getAttribute('name'), hiddenTab.getAttribute('name'));
});

test('enabling a fallback disabled tab selects it', async () => {
Expand Down
3 changes: 1 addition & 2 deletions test/cosmoz-tabs-sizing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ suite('cosmoz-tabs sizing', () => {

test('explicitly sized tabs and flex list updates size and renders only a few items upon selection', async () => {
const tabs = await fixture(html`
<cosmoz-tabs style="height: 400px" fallback-selection>
<cosmoz-tabs style="height: 400px">
<cosmoz-tab name="tab0" heading="Flex">
<iron-list id="x-list" style="flex: 1 1 0.00000001px;">
<template>
Expand All @@ -96,7 +96,6 @@ suite('cosmoz-tabs sizing', () => {
`),
list = tabs.querySelector('iron-list');

assert.isUndefined(tabs.selected);
list.items = Array.from(Array(500).keys());

tabs.selected = 'tab0';
Expand Down

0 comments on commit 086ae7d

Please sign in to comment.