-
-
Notifications
You must be signed in to change notification settings - Fork 192
feat: allow toggle relative dates on click DateTime
#847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
DateTime
0344c51 to
e7af59b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📝 WalkthroughWalkthroughThe composable 🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/nuxt/components/DateTime.spec.ts (1)
8-10: Mock should includetoggleRelativeDatesto match the new API shape.🧪 Suggested mock update
vi.mock('~/composables/useSettings', () => ({ useRelativeDates: () => ({ relativeDates: mockRelativeDates, + toggleRelativeDates: vi.fn(() => { + mockRelativeDates.value = !mockRelativeDates.value + }), }), useSettings: () => ({ settings: ref({ relativeDates: mockRelativeDates.value }), }), useAccentColor: () => ({}), }))
danielroe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there anywhere the datetime is used within a button or clickable card? I think this might be the case on package search pages.... in this case, embedding a button inside a link will be problematic
|
We have datetime in the home page (build time), package page (last published, version publish date), compare page (last published), and yes, the package search page. |
|
Perhaps we could add a prop to control whether it renders as a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
app/components/DateTime.vue (2)
12-14: Clarify numeric timestamp units.The docstring says “timestamp” but doesn’t specify units, which invites seconds-vs-milliseconds confusion. Consider making the unit explicit (or normalising numbers to
Date) to avoid ambiguous inputs.💡 Suggested clarification
- /** The datetime value (ISO string or Date or timestamp) */ + /** The datetime value (ISO string, Date, or epoch milliseconds) */
54-85: Consider adding aninteractiveprop to allow rendering as a<span>when nested in interactive elements.The
DateTimecomponent currently always renders a<button>. Whilst current usage patterns in the codebase (e.g., inPackage/Versions.vue) properly separate the component from interactive parents via container<div>elements, adding an optionalinteractiveprop to disable button rendering would make the component more flexible and prevent potential future nesting issues if used in different contexts.🛠️ Example direction (opt-in interactive mode)
<script setup lang="ts"> const props = withDefaults( defineProps<{ day?: 'numeric' | '2-digit' + /** Render as an interactive button; disable when nested in links/buttons */ + interactive?: boolean }>(), { day: undefined, + interactive: true, }, ) </script> <template> - <button type="button" :aria-pressed="relativeDates" `@click`="toggleRelativeDates"> + <component + :is="interactive ? 'button' : 'span'" + v-bind="interactive ? { type: 'button', 'aria-pressed': relativeDates } : {}" + v-on="interactive ? { click: toggleRelativeDates } : {}" + > <ClientOnly> <NuxtTime v-if="relativeDates" :datetime="datetime" :title="titleValue" relative :locale="locale" /> <NuxtTime v-else :datetime="datetime" :title="titleValue" :date-style="dateStyle" :year="year" :month="month" :day="day" :locale="locale" /> <template `#fallback`> <NuxtTime :datetime="datetime" :title="titleValue" :date-style="dateStyle" :year="year" :month="month" :day="day" :locale="locale" /> </template> </ClientOnly> - </button> + </component> </template>
| useRelativeDates: () => ({ | ||
| relativeDates: mockRelativeDates, | ||
| }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add toggleRelativeDates to the mock so clicks actually toggle.
DateTime now calls toggleRelativeDates on click, but the mock only provides relativeDates, so the new interaction test cannot flip state and will fail.
✅ Suggested fix
vi.mock('~/composables/useSettings', () => ({
useRelativeDates: () => ({
relativeDates: mockRelativeDates,
+ toggleRelativeDates: () => {
+ mockRelativeDates.value = !mockRelativeDates.value
+ },
}),
useSettings: () => ({
settings: ref({ relativeDates: mockRelativeDates.value }),
}),
useAccentColor: () => ({}),
}))📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| useRelativeDates: () => ({ | |
| relativeDates: mockRelativeDates, | |
| }), | |
| useRelativeDates: () => ({ | |
| relativeDates: mockRelativeDates, | |
| toggleRelativeDates: () => { | |
| mockRelativeDates.value = !mockRelativeDates.value | |
| }, | |
| }), |
|
I think the problem is that semantically you don't expect |
wojtekmaj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accessibility issue: button isn't labeled in a way that describes what will happen when you activate it. It's a button... With a date. That's all.
Unfortunately I don't immediately see a solution that would both keep the text using DateTime readable and properly label the button.
This PR also unifies the
NuxtTimeinapp/components/BuildEnvironment.vueto the globalDateTimecomponent.