Skip to content

Commit

Permalink
fix: add error-x-title and error-x-message slots
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Dec 5, 2024
1 parent 2cca05e commit 7bebf49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion examples/vanilla/control-elements/media-error-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,22 @@ <h2>Error 4 (MEDIA_ERR_SRC_NOT_SUPPORTED)</h2>
<h2>Error 5 (MEDIA_ERR_ENCRYPTED)</h2>
<media-error-dialog mediaerrorcode="5"></media-error-dialog>

<h2>Error 2 with custom message via <code>error-2</code> slot</h2>
<h2>Error 2 with custom error content via <code>error-2</code> slot</h2>
<media-error-dialog mediaerrorcode="2">
<h3 slot="error-2">Custom Error 2</h3>
<p slot="error-2">This is a custom message</p>
</media-error-dialog>

<h2>Error 2 with custom error title via <code>error-2-title</code> slot</h2>
<media-error-dialog mediaerrorcode="2">
<h3 slot="error-2-title">Custom Error 2 Title</h3>
</media-error-dialog>

<h2>Error 2 with custom error message via <code>error-2-message</code> slot</h2>
<media-error-dialog mediaerrorcode="2">
<p slot="error-2-message">This is a custom message</p>
</media-error-dialog>

</div>

<br>
Expand Down
4 changes: 2 additions & 2 deletions src/js/media-error-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function shouldOpenErrorDialog(error: MediaErrorLike) {
function formatErrorMessage(error: MediaErrorLike) {
const { title, message } = formatError(error) ?? {};
let html = '';
if (title) html += `<h3>${title}</h3>`;
if (message) html += `<p>${message}</p>`;
if (title) html += `<slot name="error-${error.code}-title"><h3>${title}</h3></slot>`;
if (message) html += `<slot name="error-${error.code}-message"><p>${message}</p></slot>`;
return html;
}

Expand Down

0 comments on commit 7bebf49

Please sign in to comment.