From 5ad7ecf74e24e90c2ed60a9c1af354e1ba327b7b Mon Sep 17 00:00:00 2001 From: Jeroen Claassens Date: Sat, 10 Feb 2024 10:33:29 +0100 Subject: [PATCH] fix(button): call checkType at render --- .../src/components/discord-button/DiscordButton.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/core/src/components/discord-button/DiscordButton.ts b/packages/core/src/components/discord-button/DiscordButton.ts index 6dac98213..1b2494e63 100644 --- a/packages/core/src/components/discord-button/DiscordButton.ts +++ b/packages/core/src/components/discord-button/DiscordButton.ts @@ -115,18 +115,23 @@ export class DiscordButton extends LitElement implements DiscordButtonProps { @property({ reflect: true, attribute: 'type' }) public accessor type: 'primary' | 'secondary' | 'success' | 'destructive' = 'secondary'; - public handleType(value: string) { - if (typeof value !== 'string') { + public checkType() { + if (typeof this.type !== 'string') { throw new TypeError('DiscordButton `type` prop must be a string.'); - } else if (!['primary', 'secondary', 'success', 'destructive'].includes(value)) { + } else if (!['primary', 'secondary', 'success', 'destructive'].includes(this.type)) { throw new RangeError("DiscordButton `type` prop must be one of: 'primary', 'secondary', 'success', 'destructive'"); } } - protected override render() { + public checkParentElement() { if (this.parentElement?.tagName.toLowerCase() !== 'discord-action-row') { throw new Error('All components must be direct children of .'); } + } + + protected override render() { + this.checkType(); + this.checkParentElement(); const isActive = this.url && !this.disabled;