@kubex/zinc 1.0.115 → 1.0.116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubex/zinc",
3
- "version": "1.0.115",
3
+ "version": "1.0.116",
4
4
  "description": "A collection of web components for building web applications based off of @shoelace-style/Shoelace",
5
5
  "keywords": [
6
6
  "web components",
@@ -1,7 +1,7 @@
1
1
  @use "../variables" as v;
2
2
  @use "../mixins" as m;
3
3
 
4
- table {
4
+ table:not(.remarkd-table) {
5
5
  border-collapse: separate !important;
6
6
  border-spacing: 0;
7
7
  width: 100%;
@@ -20,6 +20,7 @@ interface TabDefinition {
20
20
  sourceIndex: number;
21
21
  uri: string | null;
22
22
  slotName: string | null;
23
+ selected: boolean;
23
24
  }
24
25
 
25
26
  /**
@@ -156,6 +157,7 @@ export default class ZnPage extends ZnTabs {
156
157
  const priority = this.parsePriority(tab.getAttribute('priority'));
157
158
  const uri = tab.getAttribute('uri');
158
159
  const slotName = uri ? null : `page-tab-${index}`;
160
+ const selected = tab.hasAttribute('selected');
159
161
 
160
162
  tab.id = id;
161
163
 
@@ -163,7 +165,7 @@ export default class ZnPage extends ZnTabs {
163
165
  tab.slot = slotName!;
164
166
  }
165
167
 
166
- tabs.push({id, caption, priority, sourceIndex: index, uri, slotName});
168
+ tabs.push({id, caption, priority, sourceIndex: index, uri, slotName, selected});
167
169
  });
168
170
 
169
171
  this.tabDefinitions = tabs.sort((a, b) => this.compareTabs(a, b));
@@ -272,6 +274,12 @@ export default class ZnPage extends ZnTabs {
272
274
  }
273
275
 
274
276
  private activateInitialPageTab() {
277
+ const preselected = this.tabDefinitions.find(tab => tab.selected);
278
+ if (preselected) {
279
+ this.activateTabDefinition(preselected);
280
+ return;
281
+ }
282
+
275
283
  const selectedPanel = this.shadowRoot?.querySelector('#content > div[selected]');
276
284
  const firstTab = this.tabDefinitions[0];
277
285
 
@@ -280,6 +288,28 @@ export default class ZnPage extends ZnTabs {
280
288
  }
281
289
  }
282
290
 
291
+ private activateTabDefinition(tab: TabDefinition) {
292
+ if (tab.uri) {
293
+ const navItem = this.findNavItemForUri(tab.uri);
294
+ if (navItem) {
295
+ this.clickTab(navItem, false);
296
+ this.syncNavigationActive(navItem);
297
+ return;
298
+ }
299
+ }
300
+ this.activateTab(tab.id, false);
301
+ }
302
+
303
+ private findNavItemForUri(uri: string): HTMLElement | null {
304
+ const items = this.shadowRoot?.querySelectorAll<HTMLElement>('zn-navbar li[tab-uri]') ?? [];
305
+ for (const item of Array.from(items)) {
306
+ if (item.getAttribute('tab-uri') === uri) {
307
+ return item;
308
+ }
309
+ }
310
+ return null;
311
+ }
312
+
283
313
  private registerPagePanels() {
284
314
  this.shadowRoot?.querySelectorAll<HTMLElement>('#content > div[id]').forEach(panel => {
285
315
  this._addPanel(panel);
@@ -394,7 +424,7 @@ export default class ZnPage extends ZnTabs {
394
424
  ${this.tabDefinitions
395
425
  .filter(tab => tab.slotName !== null)
396
426
  .map(tab => html`
397
- <div id="${tab.id}">
427
+ <div id="${tab.id}" ?selected=${tab.selected}>
398
428
  <slot name="${tab.slotName!}"></slot>
399
429
  </div>
400
430
  `)}
@@ -380,6 +380,23 @@ describe('<zn-page>', () => {
380
380
  expect(getComputedStyle(activeNavItem).transitionDuration).to.equal('0.1s');
381
381
  });
382
382
 
383
+ it('opens the tab flagged with the selected attribute instead of the first', async () => {
384
+ const el = await fixture<ZnPage>(html`
385
+ <zn-page caption="Page Title">
386
+ <zn-tab caption="Overview">Overview Content</zn-tab>
387
+ <zn-tab caption="Dynamic Tab" uri="/tab-three" selected></zn-tab>
388
+ </zn-page>
389
+ `);
390
+ await aTimeout(60);
391
+
392
+ const navbar = el.shadowRoot!.querySelector('zn-navbar')!;
393
+ const uriItem = navbar.querySelector<HTMLElement>('li[tab-uri="/tab-three"]')!;
394
+ const overviewItem = navbar.querySelector<HTMLElement>('li[tab=""]')!;
395
+
396
+ expect(uriItem.classList.contains('active')).to.equal(true);
397
+ expect(overviewItem.classList.contains('active')).to.equal(false);
398
+ });
399
+
383
400
  it('disables breadcrumbs in modal mode', async () => {
384
401
  const el = await fixture<ZnPage>(html`
385
402
  <zn-page caption="Page Title" modal>
@@ -18,6 +18,8 @@ export default class ZnTab extends ZincElement {
18
18
  @property() caption: string;
19
19
  @property({type: Number}) priority: number;
20
20
  @property() uri: string;
21
+ /** When present, zn-page opens this tab on load instead of the first tab. */
22
+ @property({type: Boolean, reflect: true}) selected = false;
21
23
 
22
24
  render() {
23
25
  return html`<slot></slot>`;