Compare commits

..

3 Commits

Author SHA1 Message Date
Benjamin Canac
aabf1dd9eb chore(release): 2.0.2 2023-05-11 17:12:50 +02:00
Benjamin Canac
c7c78cb47b fix(LinkCustom): handle button when no to prop 2023-05-11 17:03:02 +02:00
Benjamin Canac
3335a6a32c docs: put back router.options.ts 2023-05-11 16:51:30 +02:00
4 changed files with 54 additions and 33 deletions

View File

@@ -2,6 +2,13 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [2.0.2](https://github.com/nuxtlabs/ui/compare/v2.0.1...v2.0.2) (2023-05-11)
### Bug Fixes
* **LinkCustom:** handle `button` when no `to` prop ([c7c78cb](https://github.com/nuxtlabs/ui/commit/c7c78cb47b00963c8a9ea0c0599fbc7e128cff66))
### [2.0.1](https://github.com/nuxtlabs/ui/compare/v2.0.0...v2.0.1) (2023-05-11)

View File

@@ -1,38 +1,48 @@
import type { RouterConfig } from '@nuxt/schema'
// https://router.vuejs.org/api/interfaces/routeroptions.html
export default <RouterConfig> {
scrollBehavior (to, _form, savedPosition) {
if (history.state.stop) { return }
if (history.state.smooth) {
return {
el: history.state.smooth,
behavior: 'smooth'
}
}
function findHashPosition (hash): { el: any, behavior: ScrollBehavior, top: number } {
const el = document.querySelector(hash)
// vue-router does not incorporate scroll-margin-top on its own.
if (el) {
const top = parseFloat(getComputedStyle(el).scrollMarginTop)
if (to.hash) {
const el = document.querySelector(to.hash) as any
if (!el) { return }
const { marginTop } = getComputedStyle(el)
const marginTopValue = parseInt(marginTop)
const offset = (document.querySelector(to.hash) as any).offsetTop - marginTopValue
return {
top: offset,
behavior: 'smooth'
}
}
// Scroll to top of window
if (savedPosition) {
return savedPosition
} else {
return { top: 0 }
return {
el: hash,
behavior: 'smooth',
top
}
}
}
// https://router.vuejs.org/api/#routeroptions
export default <RouterConfig>{
scrollBehavior (to, from, savedPosition) {
const nuxtApp = useNuxtApp()
// If history back
if (savedPosition) {
// Handle Suspense resolution
return new Promise((resolve) => {
nuxtApp.hooks.hookOnce('page:finish', () => {
setTimeout(() => resolve(savedPosition), 50)
})
})
}
// Scroll to heading on click
if (to.hash) {
return new Promise((resolve) => {
if (to.path === from.path) {
setTimeout(() => resolve(findHashPosition(to.hash)), 50)
} else {
nuxtApp.hooks.hookOnce('page:finish', () => {
setTimeout(() => resolve(findHashPosition(to.hash)), 50)
})
}
})
}
// Scroll to top of window
return { top: 0 }
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@nuxthq/ui",
"version": "2.0.1",
"version": "2.0.2",
"repository": "https://github.com/nuxtlabs/ui",
"license": "MIT",
"exports": {

View File

@@ -1,5 +1,9 @@
<template>
<button v-if="!$attrs.to" v-bind="$attrs" :class="inactiveClass">
<slot />
</button>
<NuxtLink
v-else
v-slot="{ href, navigate, exact, isActive, isExactActive }"
custom
>