Skip to content

chore(templates): extract scroll-arrows state into useScrollArrows - #145

Merged
moodyjmz merged 3 commits into
mainfrom
feat/scroll-arrows-composable
Nov 6, 2026
Merged

moodyjmz merged 3 commits into
mainfrom
feat/scroll-arrows-composable

Conversation

@moodyjmz

@moodyjmz moodyjmz commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PR 1 of #134 — proof of concept for adopting Vue composables as the layer between src/services/ (data) and src/components/ (render): stateful logic with no direct template dependency.

  • Extracts TemplateSection.vue's scroll-arrow state (list ref, canScrollLeft/canScrollRight, updateArrows(), scrollByStep(), the ResizeObserver mount/unmount wiring) into src/composables/useScrollArrows.ts, built on @vueuse/core's useScroll/useResizeObserver rather than hand-rolled — reuse-before-you-write, extended from @nextcloud/* packages to general-purpose Vue utilities.
  • Adds @vueuse/core as a direct dependency (previously only present transitively via @nextcloud/vue; both now resolve to the same 14.4.0, no duplicate copy in the tree).
  • Establishes src/composables/ and its convention for PR 2 and beyond: return individual refs (not a reactive() object — breaks silently on destructuring).
  • Closes the a11y gap noted in Adopt Vue composables for stateful non-rendering logic, starting with TemplateSection's scroll-arrows #134 while in this code: the template list now has an aria-label naming its creator.

Reuse before you write

@vueuse/core's useScroll/useResizeObserver — see commit message and #134 for the ladder rationale.

Test plan

  • npm run lint
  • npm run stylelint
  • npm run test:unit (154 passing, includes 7 new composable tests + a new a11y test)
  • npm run build

Refs #134.

🤖 Generated with Claude Code

@juliusknorr
juliusknorr marked this pull request as draft October 5, 2026 19:27
@moodyjmz
moodyjmz force-pushed the feat/scroll-arrows-composable branch from 2c7713a to 3d816bd Compare November 4, 2026 10:50
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 <noreply@anthropic.com>
Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
@moodyjmz
moodyjmz force-pushed the feat/scroll-arrows-composable branch from 3d816bd to 652ec79 Compare November 4, 2026 12:09
@moodyjmz

moodyjmz commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/compile

@moodyjmz
moodyjmz marked this pull request as ready for review November 4, 2026 20:58
@moodyjmz
moodyjmz requested a review from juliusknorr November 4, 2026 20:58
Comment thread src/components/TemplateSection.vue Outdated
<ul ref="list" class="template-section__list" @scroll="updateArrows">
<ul ref="list"
class="template-section__list"
:aria-label="t('office', '{creator} templates, scrollable', { creator: creator.label })">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to drop the ", scrollable" part? Screen readers would already announce it as a list with N items, and the cards are plain buttons, so keyboard users get there anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, dropped. The label is now just {creator} templates.

Comment thread src/composables/useScrollArrows.spec.ts Outdated

expect(resizeObserverInstances[0].disconnect).toHaveBeenCalled()
globalThis.ResizeObserver = OriginalResizeObserver
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test just tests vue-use internal behaviour so i would argue we can drop it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped. It was the only user of withSetup, so that helper is gone too.

@juliusknorr juliusknorr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup 👍

Minor comments in line and i would not consider this a feat but rather a chore commit (also for proper positioning in the changelog).

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 <noreply@anthropic.com>
Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
@moodyjmz
moodyjmz force-pushed the feat/scroll-arrows-composable branch from e563261 to d599975 Compare November 6, 2026 08:32
@moodyjmz

moodyjmz commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/compile

@moodyjmz moodyjmz changed the title feat(templates): extract scroll-arrows state into useScrollArrows chore(templates): extract scroll-arrows state into useScrollArrows Nov 6, 2026
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
@moodyjmz
moodyjmz merged commit 708e2b6 into main Nov 6, 2026
25 checks passed
@moodyjmz
moodyjmz deleted the feat/scroll-arrows-composable branch November 6, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants