Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ”’ Prevent window.opener access and ensure keyboard focusability for popout button

github-actions[bot]a69bae57ee59
diff --git a/src/components/Workspace/SideBarItem.vue b/src/components/Workspace/SideBarItem.vue
index 598a541b..1e3fa19b 100644
--- a/src/components/Workspace/SideBarItem.vue
+++ b/src/components/Workspace/SideBarItem.vue
@@ -53,7 +53,7 @@ export default {
},
openInNewTab(e) {
if (e && e.preventDefault) e.preventDefault();
- if (this.url) window.open(this.url, '_blank');
+ if (this.url) window.open(this.url, '_blank', 'noopener,noreferrer');
},
},
data() {
@@ -88,7 +88,9 @@ div.side-bar-item {
}
.popout-btn {
- display: none;
+ display: flex;
+ align-items: center;
+ justify-content: center;
position: absolute;
top: 50%;
right: 4px;
@@ -98,23 +100,29 @@ div.side-bar-item {
cursor: pointer;
padding: 2px;
color: currentColor;
- opacity: 0.7;
+ opacity: 0;
+ pointer-events: none;
border-radius: var(--curve-factor, 4px);
transition: opacity 0.15s ease-in-out, background 0.15s ease-in-out;
- &:hover {
+
+ &:hover,
+ &:focus-visible {
opacity: 1;
background: rgba(255, 255, 255, 0.15);
+ outline: 1px solid currentColor;
+ pointer-events: auto;
}
+
svg {
width: 0.75rem;
height: 0.75rem;
}
}
- &:hover .popout-btn {
- display: flex;
- align-items: center;
- justify-content: center;
+ &:hover .popout-btn,
+ &:focus-within .popout-btn {
+ opacity: 0.7;
+ pointer-events: auto;
}
}
</style>
diff --git a/tests/components/sidebar-item.test.js b/tests/components/sidebar-item.test.js
index ed98795b..030aba4c 100644
--- a/tests/components/sidebar-item.test.js
+++ b/tests/components/sidebar-item.test.js
@@ -70,26 +70,26 @@ describe('SideBarItem', () => {
const popoutBtn = wrapper.find('.popout-btn');
expect(popoutBtn.exists()).toBe(true);
await popoutBtn.trigger('click');
- expect(openSpy).toHaveBeenCalledWith('https://example.com', '_blank');
+ expect(openSpy).toHaveBeenCalledWith('https://example.com', '_blank', 'noopener,noreferrer');
expect(wrapper.emitted('launch-app')).toBeFalsy();
});
it('opens in new tab when clicked with ctrlKey or metaKey', async () => {
const wrapper = mountItem({ title: 'App', url: 'https://example.com', target: 'workspace' });
await wrapper.trigger('click', { ctrlKey: true });
- expect(openSpy).toHaveBeenCalledWith('https://example.com', '_blank');
+ expect(openSpy).toHaveBeenCalledWith('https://example.com', '_blank', 'noopener,noreferrer');
expect(wrapper.emitted('launch-app')).toBeFalsy();
openSpy.mockClear();
await wrapper.trigger('click', { metaKey: true });
- expect(openSpy).toHaveBeenCalledWith('https://example.com', '_blank');
+ expect(openSpy).toHaveBeenCalledWith('https://example.com', '_blank', 'noopener,noreferrer');
expect(wrapper.emitted('launch-app')).toBeFalsy();
});
it('opens in new tab when middle clicked (auxclick button 1)', async () => {
const wrapper = mountItem({ title: 'App', url: 'https://example.com', target: 'workspace' });
await wrapper.trigger('auxclick', { button: 1 });
- expect(openSpy).toHaveBeenCalledWith('https://example.com', '_blank');
+ expect(openSpy).toHaveBeenCalledWith('https://example.com', '_blank', 'noopener,noreferrer');
});
});