Skip to content
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

feat(docs): the official website adds API anchor function #2366

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions examples/sites/src/views/components/components.vue
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@

<script lang="jsx">
import { defineComponent, reactive, computed, toRefs, watch, onMounted, ref, onUnmounted, nextTick } from 'vue'
import { useRoute } from 'vue-router'
import { marked } from 'marked'
import hljs from 'highlight.js'
import { Anchor, ButtonGroup, Grid, GridColumn, Tabs, TabItem, Tooltip } from '@opentiny/vue'
Expand Down Expand Up @@ -279,6 +280,8 @@ export default defineComponent({
const isRunningTest = localStorage.getItem('tiny-e2e-test') === 'true'
const anchorRefreshKey = ref(0)
const apiTableRef = ref()
const route = useRoute()

const state = reactive({
webDocPath: computed(() => ''),
langKey: getWord('zh-CN', 'en-US'),
Expand Down Expand Up @@ -310,7 +313,7 @@ export default defineComponent({
currAnchorLinks: computed(() => (state.activeTab === 'demos' ? state.demoAnchorLinks : state.apiAnchorLinks)),
// 单demo显示时
singleDemo: null,
activeTab: 'demos',
activeTab: route.hash === '#api' ? 'api' : 'demos',
tableData: {},
currApiTypes: [],
showApiTab: computed(() => state.currApiTypes.length),
Expand Down Expand Up @@ -616,7 +619,8 @@ export default defineComponent({
copyText: (text) => {
navigator.clipboard.writeText(text)
},
onTabsClick: () => {
onTabsClick: (data) => {
router.push(`#${data.name}`)
scrollToLayoutTop()
Comment on lines +622 to 624
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider conditional scroll behavior for tab switching.

The current implementation always scrolls to the top when switching tabs. This might not be the desired behavior when switching to the API tab, as users might want to maintain their scroll position.

Consider updating the implementation to only scroll when necessary:

 onTabsClick: (data) => {
   router.push(`#${data.name}`)
-  scrollToLayoutTop()
+  if (data.name !== 'api') {
+    scrollToLayoutTop()
+  }
 }
📝 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.

Suggested change
onTabsClick: (data) => {
router.push(`#${data.name}`)
scrollToLayoutTop()
onTabsClick: (data) => {
router.push(`#${data.name}`)
if (data.name !== 'api') {
scrollToLayoutTop()
}

},
// 点击 api区域的 name列时
Expand Down
Loading