fix: bool-on props broken in generic setter dispatcher

parseAttributeValue('') returns '' (falsy) for boolean-present
attributes, making setDraggable(false), setInteractive(''), etc.
not work. Now looks up the prop spec from PROPS and passes
val !== null (true/false) when kind is 'bool-on'.

Fixes: leaflet-marker, leaflet-tile-layer-wms, leaflet-image-overlay,
leaflet-video-overlay, leaflet-svg-overlay, leaflet-geojson
main
Buddy 3 months ago
parent 78c39f33a3
commit be84e61ad0

@ -66,7 +66,9 @@ export class LeafletGeoJSON extends withProps(HTMLElement, PROPS) {
} else {
const propName = PROP_BY_ATTR.get(name);
if (!propName) return;
this.#obj.setStyle({ [propName]: val } as PathOptions);
const spec = PROPS[propName as keyof typeof PROPS];
const styleVal = spec.kind === 'bool-on' ? val !== null : val;
this.#obj.setStyle({ [propName]: styleVal } as PathOptions);
}
}
}

@ -61,7 +61,9 @@ export class LeafletImageOverlay extends withProps(HTMLElement, PROPS) {
const setter =
`set${propName.charAt(0).toUpperCase()}${propName.slice(1)}` as keyof ImageOverlay;
if (typeof this.#obj[setter] === 'function') {
(this.#obj[setter] as (v: unknown) => void)(parseAttributeValue(val));
const spec = PROPS[propName as keyof typeof PROPS];
const value = spec.kind === 'bool-on' ? val !== null : parseAttributeValue(val);
(this.#obj[setter] as (v: unknown) => void)(value);
}
}
}

@ -57,7 +57,9 @@ export class LeafletMarker extends withProps(HTMLElement, PROPS) {
if (!propName) return;
const setter = `set${propName.charAt(0).toUpperCase()}${propName.slice(1)}` as keyof Marker;
if (typeof this.#obj[setter] === 'function') {
(this.#obj[setter] as (v: unknown) => void)(parseAttributeValue(val));
const spec = PROPS[propName as keyof typeof PROPS];
const value = spec.kind === 'bool-on' ? val !== null : parseAttributeValue(val);
(this.#obj[setter] as (v: unknown) => void)(value);
}
}
}

@ -57,7 +57,9 @@ export class LeafletSVGOverlay extends withProps(HTMLElement, PROPS) {
const setter =
`set${propName.charAt(0).toUpperCase()}${propName.slice(1)}` as keyof SVGOverlay;
if (typeof this.#obj[setter] === 'function') {
(this.#obj[setter] as (v: unknown) => void)(parseAttributeValue(val));
const spec = PROPS[propName as keyof typeof PROPS];
const value = spec.kind === 'bool-on' ? val !== null : parseAttributeValue(val);
(this.#obj[setter] as (v: unknown) => void)(value);
}
}
}

@ -55,11 +55,14 @@ export class LeafletTileLayerWMS extends withProps(HTMLElement, PROPS) {
if (!propName) return;
const setter =
`set${propName.charAt(0).toUpperCase()}${propName.slice(1)}` as keyof TileLayer.WMS;
const spec = PROPS[propName as keyof typeof PROPS];
if (typeof this.#obj[setter] === 'function') {
(this.#obj[setter] as (v: unknown) => void)(parseAttributeValue(val));
const value = spec.kind === 'bool-on' ? val !== null : parseAttributeValue(val);
(this.#obj[setter] as (v: unknown) => void)(value);
} else {
const value = spec.kind === 'bool-on' ? val !== null : parseAttributeValue(val);
(this.#obj.setParams as unknown as (params: Record<string, unknown>) => void)({
[propName]: parseAttributeValue(val),
[propName]: value,
});
}
}

@ -62,7 +62,9 @@ export class LeafletVideoOverlay extends withProps(HTMLElement, PROPS) {
const setter =
`set${propName.charAt(0).toUpperCase()}${propName.slice(1)}` as keyof VideoOverlay;
if (typeof this.#obj[setter] === 'function') {
(this.#obj[setter] as (v: unknown) => void)(parseAttributeValue(val));
const spec = PROPS[propName as keyof typeof PROPS];
const value = spec.kind === 'bool-on' ? val !== null : parseAttributeValue(val);
(this.#obj[setter] as (v: unknown) => void)(value);
}
}
}

Loading…
Cancel
Save