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

Toast: Prevent error being thrown if opened without returnElements setting #572

Merged
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
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@
"contributions": [
"code"
]
},
{
"login": "brentswisher",
"name": "Brent Swisher",
"avatar_url": "https://avatars.githubusercontent.com/u/6653970?v=4",
"profile": "http://brentswisher.com/",
"contributions": [
"bug",
"code"
]
}
],
"contributorsPerLine": 7
Expand Down
5 changes: 5 additions & 0 deletions .changeset/sweet-eyes-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ithaka/pharos': patch
---

Update toaster to not error on toast close if returnElements wasn't provided
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/drewgingerich"><img src="https://avatars.githubusercontent.com/u/15133892?v=4?s=100" width="100px;" alt="Drew Gingerich"/><br /><sub><b>Drew Gingerich</b></sub></a><br /><a href="https://github.com/ithaka/pharos/commits?author=drewgingerich" title="Documentation">📖</a> <a href="https://github.com/ithaka/pharos/commits?author=drewgingerich" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/HassanTanveer"><img src="https://avatars.githubusercontent.com/u/57575219?v=4?s=100" width="100px;" alt="Hassan Tanveer"/><br /><sub><b>Hassan Tanveer</b></sub></a><br /><a href="https://github.com/ithaka/pharos/commits?author=HassanTanveer" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mariadevadoss"><img src="https://avatars.githubusercontent.com/u/132926833?v=4?s=100" width="100px;" alt="mariadevadoss"/><br /><sub><b>mariadevadoss</b></sub></a><br /><a href="https://github.com/ithaka/pharos/commits?author=mariadevadoss" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://brentswisher.com/"><img src="https://avatars.githubusercontent.com/u/6653970?v=4?s=100" width="100px;" alt="Brent Swisher"/><br /><sub><b>Brent Swisher</b></sub></a><br /><a href="https://github.com/ithaka/pharos/issues?q=author%3Abrentswisher" title="Bug reports">🐛</a> <a href="https://github.com/ithaka/pharos/commits?author=brentswisher" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ describe('pharos-toaster', () => {
const event = new CustomEvent('pharos-toast-open', {
detail: {
content: 'I am a toast',
returnElements: [],
},
});
document.dispatchEvent(event);
Expand Down
6 changes: 4 additions & 2 deletions packages/pharos/src/components/toast/pharos-toaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { DEFAULT_STATUS, DEFAULT_INDEFINITE } from './pharos-toast';

import { v4 as uuidv4 } from 'uuid';

const DEFAULT_RETURN_ELEMENTS: Array<HTMLElement> = [];

/**
* pharos-toast-open event.
*
Expand All @@ -27,7 +29,7 @@ import { v4 as uuidv4 } from 'uuid';
* @listens pharos-toast-open
*/
export class PharosToaster extends PharosElement {
private returnElements: Array<HTMLElement> = [];
private returnElements = DEFAULT_RETURN_ELEMENTS;

constructor() {
super();
Expand Down Expand Up @@ -63,7 +65,7 @@ export class PharosToaster extends PharosElement {
const toast = document.createElement(toastTag) as PharosToast;
const { content, status, id, indefinite, returnElements } = (<CustomEvent>event).detail;

this.returnElements = returnElements;
this.returnElements = returnElements ?? DEFAULT_RETURN_ELEMENTS;
toast.innerHTML = content;
toast.status = status || DEFAULT_STATUS;
toast.id = this._getToastID(id);
Expand Down
Loading