Skip to content

Commit

Permalink
Add a componentReady event (#99)
Browse files Browse the repository at this point in the history
* add a new componentReady event

Useful for when you need to check for things like startDate from outside the web component
  • Loading branch information
brinkofblink authored Feb 1, 2024
1 parent 4ac058e commit 2ed8a97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,13 @@ <h2 id="events">Events</h2>
</td>
<td>Fired when the displayed month or year changes.</td>
</tr>
<tr>
<td>componentReady</td>
<td>
<code>CustomEvent&lt;void&gt;</code>
</td>
<td>Fired when this component is fully loaded at the first render.</td>
</tr>
</tbody>
</table>
</div>
Expand All @@ -739,7 +746,12 @@ <h2 id="events">Events</h2>
datepicker.addEventListener('selectDate', function(event) {
console.log(event.detail);
});
&lt;/script&gt;</code></pre>

datepicker.addEventListener('componentReady', function(event) {
console.log(datepicker.startDate);
});
&lt;/script&gt;
</code></pre>
</section>

<section>
Expand Down
3 changes: 3 additions & 0 deletions src/components/inclusive-dates/inclusive-dates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export class InclusiveDates {

@Event() selectDate: EventEmitter<string | string[] | undefined>;

@Event() componentReady: EventEmitter<void>;

private modalRef?: HTMLInclusiveDatesModalElement;
private inputRef?: HTMLInputElement;
private calendarButtonRef?: HTMLButtonElement;
Expand All @@ -148,6 +150,7 @@ export class InclusiveDates {
private errorMessage = "";

componentDidLoad() {
this.componentReady.emit();
if (!this.id) {
console.error(
'inclusive-dates: The "id" prop is required for accessibility'
Expand Down

0 comments on commit 2ed8a97

Please sign in to comment.