Skip to content
Open
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
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function ShortcutButtonsPlugin(config: ShortcutButtonsFlatpickr.Config) {
/**
* Element that wraps this plugin's dependent elements.
*/
let wrapper: HTMLElement;
let wrapper: HTMLElement | undefined;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcsmorais can be undefined bc its set to undefined onDestroy(), I get TS errors if it's not defined that way


/**
* Handles click events on plugin's button.
Expand All @@ -88,7 +88,7 @@ export function ShortcutButtonsPlugin(config: ShortcutButtonsFlatpickr.Config) {
return;
}

const index = parseInt(target.dataset.index, 10);
const index = parseInt(target.dataset.index as string, 10);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcsmorais index could be undefined, that's why I get TS error -->
grafik


const callbacks: ShortcutButtonsFlatpickr.OnClickSignature[] = Array.isArray(cfg.onClick) ?
cfg.onClick :
Expand Down Expand Up @@ -119,7 +119,7 @@ export function ShortcutButtonsPlugin(config: ShortcutButtonsFlatpickr.Config) {
/**
* Set given button's attributes.
*/
function setButtonsAttributes(button: HTMLButtonElement, attributes?: ShortcutButtonsFlatpickr.Attributes) {
function setButtonsAttributes(button: HTMLButtonElement, attributes: ShortcutButtonsFlatpickr.Attributes) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcsmorais your are checking for undefined before calling this function, no need for attributes to be optional
grafik

Object.keys(attributes).filter((attribute) => supportedAttributes.has(attribute)).forEach((key) => {
if (key === 'class') {
button.classList.add(attributes[key]);
Expand All @@ -136,7 +136,7 @@ export function ShortcutButtonsPlugin(config: ShortcutButtonsFlatpickr.Config) {
*/
onReady: () => {
wrapper = document.createElement('div');
wrapper.classList.add('shortcut-buttons-flatpickr-wrapper', cfg.theme);
wrapper.classList.add('shortcut-buttons-flatpickr-wrapper', cfg.theme as string);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcsmorais theme is defined as string | undefined (gives TS error) but you're always setting a default theme, therefore it's never undefined at this point, simpliest way is to use "as string"


if (typeof cfg.label !== 'undefined' && cfg.label.length) {
const label = document.createElement('div');
Expand Down Expand Up @@ -176,6 +176,7 @@ export function ShortcutButtonsPlugin(config: ShortcutButtonsFlatpickr.Config) {
* Clean up before flatpickr is destroyed.
*/
onDestroy: () => {
if (typeof wrapper === 'undefined') return;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcsmorais changed this alike your suggestion

wrapper.removeEventListener('keydown', onKeyDown);
wrapper.removeEventListener('click', onClick);
wrapper = undefined;
Expand Down