Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/anchorableNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export function anchorableElement(element) {
if (link.dataset.nullstack) return
link.dataset.nullstack = true
link.addEventListener('click', (event) => {
if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
if (!event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
event.preventDefault()
router.url = link.getAttribute('href')
}
})
}
}
}
4 changes: 2 additions & 2 deletions plugins/anchorable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function transform({ node, router }) {
const originalEvent = node.attributes.onclick
node.attributes.default = true
node.attributes.onclick = ({ event }) => {
if (!event.ctrlKey && !event.shiftKey && !event.altKey) {
if (!event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
event.preventDefault()
router.url = node.attributes.href
}
Expand All @@ -25,4 +25,4 @@ function transform({ node, router }) {
}
}

export default { transform, client: true }
export default { transform, client: true }
18 changes: 17 additions & 1 deletion tests/src/AnchorModifiers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ describe('AnchorModifiers jsx', () => {
expect(url).toEqual('http://localhost:6969/anchor-modifiers');
});

test('Clicking html link with cmd opens in new window', async () => {
await page.keyboard.down('Meta');
await page.click('[href="/anchor-modifiers?source=html"]');
await page.keyboard.up('Meta');
const url = await page.url()
expect(url).toEqual('http://localhost:6969/anchor-modifiers');
});

test('Clicking html link with alt downloads the link', async () => {
await page.keyboard.down('Alt');
await page.click('[href="/anchor-modifiers?source=html"]');
Expand All @@ -44,6 +52,14 @@ describe('AnchorModifiers jsx', () => {
expect(url).toEqual('http://localhost:6969/anchor-modifiers');
});

test('Clicking jsx link with cmd opens in new window', async () => {
await page.keyboard.down('Meta');
await page.click('[href="/anchor-modifiers?source=jsx"]');
await page.keyboard.up('Meta');
const url = await page.url()
expect(url).toEqual('http://localhost:6969/anchor-modifiers');
});

test('Clicking jsx link with alt downloads the link', async () => {
await page.keyboard.down('Alt');
await page.click('[href="/anchor-modifiers?source=jsx"]');
Expand All @@ -70,4 +86,4 @@ describe('AnchorModifiers jsx', () => {
expect(element).toBeTruthy();
});

});
});