Skip to content

Commit

Permalink
tidy web component constructor() funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
basher committed Jan 17, 2025
1 parent 6e8e871 commit e6fb965
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ui/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "web-ui-boilerplate",
"description": "UI boilerplate for websites/webapps using vanilla HTML/CSS/JavaScript, powered by Storybook, bundled by Parcel.",
"author": "basher",
"version": "4.0.9",
"version": "4.0.10",
"license": "ISC",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion ui/src/javascript/web-components/webui-disclosure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class WebUIDisclosure extends HTMLElement {

this.setupA11y();

this.trigger?.addEventListener('click', this);
this.trigger.addEventListener('click', this);
}

private setupA11y(): void {
Expand Down
9 changes: 3 additions & 6 deletions ui/src/javascript/web-components/webui-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default class WebUIModal extends HTMLElement {

this.setupA11y();

this.btnModalOpen?.addEventListener('click', this);
this.btnModalOpen?.addEventListener('keydown', this);
this.btnModalOpen.addEventListener('click', this);
this.btnModalOpen.addEventListener('keydown', this);
this.btnsModalClose.forEach((btnModalClose) => {
btnModalClose?.addEventListener('click', this);
});
Expand Down Expand Up @@ -71,15 +71,12 @@ export default class WebUIModal extends HTMLElement {
public handleEvent(e: KeyboardEvent) {
const target = e.currentTarget as HTMLButtonElement;

// Ensure <a role="button"> can open modal with ENTER and SPACEBAR.
// Ensure button can open modal with ENTER and SPACEBAR.
if (e.type === 'keydown' && e.code !== 'Enter' && e.code !== 'Space')
return;

// Click 'open' button.
if (target?.dataset.open === '') {
// Prevent default behaviour on <a role="button">.
e.preventDefault();

this.handleOpen();
}

Expand Down
5 changes: 4 additions & 1 deletion ui/src/javascript/web-components/webui-notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ export default class WebUINotify extends HTMLElement {
constructor() {
super();
this.btnClose = this.querySelector('[data-close]');
this.btnClose?.addEventListener('click', this);

if (!this.btnClose) return;

this.btnClose.addEventListener('click', this);
}

// Handle constructor() event listeners.
Expand Down
2 changes: 1 addition & 1 deletion ui/src/javascript/web-components/webui-share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class WebUIShare extends HTMLElement {

if (!this.btnShare) return;

this.btnShare?.addEventListener('click', this);
this.btnShare.addEventListener('click', this);
this.btnCopy?.addEventListener('click', this);
}

Expand Down

0 comments on commit e6fb965

Please sign in to comment.