Skip to content

Commit 572af3b

Browse files
Ensure link has href; Expand docs
1 parent 861767c commit 572af3b

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
. "$(dirname "$0")/_/husky.sh"
33

44
npm test
5+
npm run build:esm

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import ResetViewControl from '@20tab/react-leaflet-resetview';
2424
const Map = () => {
2525
return (
2626
<MapContainer zoom={5} center={[-96.8716348, 32.8205866]}>
27-
<ResetViewControl title="Reset view" />
27+
<ResetViewControl
28+
title="Reset view"
29+
icon="url(/some/relative/path.png)"
30+
/>
2831
</MapContainer>
2932
);
3033
};

__tests__/ResetViewControl.spec.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,9 @@ describe("ResetViewControl", () => {
5353
"background-image": "url(/some/relative/path.png)",
5454
});
5555
});
56+
57+
test("link has href", () => {
58+
render(<Map />);
59+
expect(screen.getByTitle("Reset view")).toHaveAttribute("href", "#");
60+
});
5661
});

src/ResetViewControl.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@ const _getControl = Control.extend({
3535

3636
const container = DomUtil.create("div", "leaflet-bar");
3737
const link = DomUtil.create("a", "", container);
38-
link.setAttribute("title", title);
38+
39+
const linkAttrs = {
40+
title,
41+
href: "#",
42+
};
43+
44+
Object.entries(linkAttrs).forEach(([k, v]) => {
45+
link.setAttribute(k, v);
46+
});
47+
3948
link.innerHTML = icon;
4049

4150
if (RegExp(/url\(.+\)/).test(icon)) {

0 commit comments

Comments
 (0)