diff --git a/src/label.ts b/src/label.ts index 0c7ed9e..048c2c8 100644 --- a/src/label.ts +++ b/src/label.ts @@ -91,6 +91,20 @@ export class Label extends OverlayViewSafe { } } + /** + * Get the class of the label div elements. + * + * **Note**: This will always return the default `marker-label`. + */ + get className(): string { + return this.labelDiv.className; + } + + /** + * Set the class of the label div elements. + * + * **Note**: The default `marker-label` will additionaly be added. + */ set className(className: string) { this.labelDiv.className = className; this.labelDiv.classList.add(LABEL_CLASS); diff --git a/src/marker.test.ts b/src/marker.test.ts index 56aff87..b60492a 100644 --- a/src/marker.test.ts +++ b/src/marker.test.ts @@ -100,3 +100,10 @@ test("should not have interactive listeners if no map", () => { 0 ); }); + +test("should set class on label", () => { + const marker = new MarkerWithLabel({ labelContent: "foo" }); + const className = "bar baz"; + marker.labelClass = className; + expect(marker.labelClass).toMatch(className); +}); diff --git a/src/marker.ts b/src/marker.ts index 325e7fe..630eeab 100644 --- a/src/marker.ts +++ b/src/marker.ts @@ -89,6 +89,14 @@ export class MarkerWithLabel extends MarkerSafe { return this.getClickable() || this.getDraggable(); } + get labelClass() { + return this.label.className; + } + + set labelClass(className: string) { + this.label.className = className; + } + setMap(map: google.maps.Map | google.maps.StreetViewPanorama | null): void { super.setMap(map); setTimeout(() => {