From 08f996d181cfbb6c09faecafa60d1230004d8b2c Mon Sep 17 00:00:00 2001 From: James Manuel Date: Fri, 28 Aug 2026 09:17:00 +0200 Subject: [PATCH 1/3] build(deps): add @vueuse/core as a direct dependency Already present transitively via @nextcloud/vue, but the app is about to import from it directly (useScrollArrows), so it needs to be declared rather than relied on implicitly. Assisted-by: ClaudeCode:claude Co-Authored-By: Claude Signed-off-by: James Manuel --- package-lock.json | 1 + package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/package-lock.json b/package-lock.json index e62532df..b0aced49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "@nextcloud/l10n": "^3.4.1", "@nextcloud/router": "^3.1.0", "@nextcloud/vue": "^9.13.1", + "@vueuse/core": "^14.4.0", "vue": "^3.5.43", "vue-router": "^5.3.1" }, diff --git a/package.json b/package.json index 2126f6e1..a58a231a 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@nextcloud/l10n": "^3.4.1", "@nextcloud/router": "^3.1.0", "@nextcloud/vue": "^9.13.1", + "@vueuse/core": "^14.4.0", "vue": "^3.5.43", "vue-router": "^5.3.1" }, From d599975585115c0750a3b8f48cbe5411b6d2a00b Mon Sep 17 00:00:00 2001 From: James Manuel Date: Fri, 28 Aug 2026 09:17:10 +0200 Subject: [PATCH 2/3] chore(templates): extract scroll-arrows state into useScrollArrows TemplateSection.vue's list ref, canScrollLeft/canScrollRight, updateArrows(), scrollByStep(), and the ResizeObserver onMounted/ onUnmounted wiring were stateful logic with no direct template dependency, inline in the component. Pulled into a composable built on @vueuse/core's useScroll/useResizeObserver instead of hand-rolled scroll tracking, following the reuse-before-you-write ladder. Establishes src/composables/ and its convention for later extractions: individual refs returned (not a reactive() object, which breaks destructuring). Also gives the template list an aria-label naming the creator, so screen readers can tell one creator's list from another's. PR 1 of #134. Assisted-by: ClaudeCode:claude Co-Authored-By: Claude Signed-off-by: James Manuel --- src/components/TemplateSection.spec.ts | 40 ++++++++--- src/components/TemplateSection.vue | 49 ++++---------- src/composables/useScrollArrows.spec.ts | 88 +++++++++++++++++++++++++ src/composables/useScrollArrows.ts | 53 +++++++++++++++ 4 files changed, 185 insertions(+), 45 deletions(-) create mode 100644 src/composables/useScrollArrows.spec.ts create mode 100644 src/composables/useScrollArrows.ts diff --git a/src/components/TemplateSection.spec.ts b/src/components/TemplateSection.spec.ts index e440ab21..2fe1bccf 100644 --- a/src/components/TemplateSection.spec.ts +++ b/src/components/TemplateSection.spec.ts @@ -1,4 +1,5 @@ import { mount } from '@vue/test-utils' +import { nextTick } from 'vue' import { beforeEach, describe, expect, it, vi } from 'vitest' import TemplateSection from './TemplateSection.vue' import type { TemplateCreator, TemplateFile } from '../services/templates.ts' @@ -142,26 +143,45 @@ describe('TemplateSection > themeType', () => { }) }) +describe('TemplateSection > accessibility', () => { + it('labels the list with the creator name', () => { + const creator = makeCreator({ label: 'Spreadsheet' }) + const wrapper = mount(TemplateSection, { props: { creator } }) + + expect(wrapper.find('.template-section__list').attributes('aria-label')) + .toBe('Spreadsheet templates') + }) +}) + describe('TemplateSection > scroll arrows', () => { function setScrollMetrics(el: HTMLElement, { scrollLeft = 0, scrollWidth = 0, clientWidth = 0 }) { - Object.defineProperty(el, 'scrollLeft', { value: scrollLeft, configurable: true }) + Object.defineProperty(el, 'scrollLeft', { value: scrollLeft, writable: true, configurable: true }) Object.defineProperty(el, 'scrollWidth', { value: scrollWidth, configurable: true }) Object.defineProperty(el, 'clientWidth', { value: clientWidth, configurable: true }) } - it('hides the nav entirely when the list does not overflow', () => { - const creator = makeCreator() + // useScrollArrows attaches its scroll listener from a watcher that only + // runs once Vue flushes post-render effects — mount() itself doesn't wait + // for that, so anything dispatched immediately after would be missed. + async function mountAndSettle(creator: TemplateCreator) { const wrapper = mount(TemplateSection, { props: { creator } }) - setScrollMetrics(wrapper.find('.template-section__list').element as HTMLElement, { - scrollLeft: 0, scrollWidth: 100, clientWidth: 100, - }) + await nextTick() + return wrapper + } + + it('hides the nav entirely when the list does not overflow', async () => { + const creator = makeCreator() + const wrapper = await mountAndSettle(creator) + const list = wrapper.find('.template-section__list').element as HTMLElement + setScrollMetrics(list, { scrollLeft: 0, scrollWidth: 100, clientWidth: 100 }) + await wrapper.find('.template-section__list').trigger('scroll') expect(wrapper.find('.template-section__nav').exists()).toBe(false) }) it('enables the right arrow (not left) when scrolled to the start of an overflowing list', async () => { const creator = makeCreator() - const wrapper = mount(TemplateSection, { props: { creator } }) + const wrapper = await mountAndSettle(creator) const list = wrapper.find('.template-section__list').element as HTMLElement setScrollMetrics(list, { scrollLeft: 0, scrollWidth: 500, clientWidth: 200 }) await wrapper.find('.template-section__list').trigger('scroll') @@ -173,7 +193,7 @@ describe('TemplateSection > scroll arrows', () => { it('enables the left arrow (not right) when scrolled to the end of an overflowing list', async () => { const creator = makeCreator() - const wrapper = mount(TemplateSection, { props: { creator } }) + const wrapper = await mountAndSettle(creator) const list = wrapper.find('.template-section__list').element as HTMLElement setScrollMetrics(list, { scrollLeft: 300, scrollWidth: 500, clientWidth: 200 }) await wrapper.find('.template-section__list').trigger('scroll') @@ -185,7 +205,7 @@ describe('TemplateSection > scroll arrows', () => { it('scrolls right by max(card+gap, clientWidth - (card+gap))', async () => { const creator = makeCreator() - const wrapper = mount(TemplateSection, { props: { creator } }) + const wrapper = await mountAndSettle(creator) const list = wrapper.find('.template-section__list').element as HTMLElement // CARD_WIDTH=160, CARD_GAP=12: card+gap=172, clientWidth-172=28 -> max is 172. setScrollMetrics(list, { scrollLeft: 0, scrollWidth: 500, clientWidth: 200 }) @@ -199,7 +219,7 @@ describe('TemplateSection > scroll arrows', () => { it('scrolls left as a negative step when the left arrow is clicked', async () => { const creator = makeCreator() - const wrapper = mount(TemplateSection, { props: { creator } }) + const wrapper = await mountAndSettle(creator) const list = wrapper.find('.template-section__list').element as HTMLElement setScrollMetrics(list, { scrollLeft: 300, scrollWidth: 500, clientWidth: 200 }) await wrapper.find('.template-section__list').trigger('scroll') diff --git a/src/components/TemplateSection.vue b/src/components/TemplateSection.vue index c02c59c2..4efa5d53 100644 --- a/src/components/TemplateSection.vue +++ b/src/components/TemplateSection.vue @@ -4,12 +4,13 @@ -->