Skip to content

Instantly share code, notes, and snippets.

View peteygao's full-sized avatar
💭
Writing Elm @ Selph.ai

Peter Gao peteygao

💭
Writing Elm @ Selph.ai
View GitHub Profile
@peteygao
peteygao / expandable-text.js
Created November 24, 2023 08:14
Expandable Text web component (hide text behind a "Read more" button)
class ExpandableText extends HTMLElement {
private shadow: ShadowRoot;
private container: HTMLDivElement;
private readMoreBtn: HTMLSpanElement;
private expanded: boolean;
private containerLargerThanText: boolean;
constructor() {
super();
this.shadow = this.attachShadow({ mode: 'open' });