Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs: fire event when tab selected programmatically #442

Merged
merged 1 commit into from
Nov 7, 2022
Merged
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
5 changes: 5 additions & 0 deletions .changeset/six-days-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ithaka/pharos': minor
---

Fire pharos-tab-selected in response to tab being selected programmatically in addition to user clicks
15 changes: 9 additions & 6 deletions packages/pharos/src/components/tabs/pharos-tab.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PharosElement } from '../base/pharos-element';
import { html } from 'lit';
import { property, state } from 'lit/decorators.js';
import type { TemplateResult, CSSResultArray, PropertyValues } from 'lit';

import { PharosElement } from '../base/pharos-element';
import { tabStyles } from './pharos-tab.css';

/**
Expand Down Expand Up @@ -43,19 +44,21 @@ export class PharosTab extends PharosElement {
if (changedProperties.has('selected')) {
this._focused = this.selected;
this.setAttribute('aria-selected', this.selected ? 'true' : 'false');
if (this.selected) {
const details = {
bubbles: true,
composed: true,
};
this.dispatchEvent(new CustomEvent('pharos-tab-selected', details));
}
}
if (changedProperties.has('_focused')) {
this.setAttribute('tabindex', this._focused ? '0' : '-1');
}
}

private _handleClick(): void {
const details = {
bubbles: true,
composed: true,
};
this.selected = true;
this.dispatchEvent(new CustomEvent('pharos-tab-selected', details));
}

protected override render(): TemplateResult {
Expand Down