Skip to content

Commit 4f2840c

Browse files
committed
[r96943502] fix: prevent jumping issues
1 parent eb97459 commit 4f2840c

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

src/components/ContentNode/LinkableHeading.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
:is="`h${level}`"
1515
class="section-title"
1616
>
17-
<a
17+
<router-link
1818
v-if="anchor && !isTargetIDE"
19-
:href="`#${anchor}`"
19+
:to="{ hash: `#${anchor}` }"
2020
class="header-anchor"
2121
aria-label="hidden"
2222
@click="handleFocusAndScroll(anchor)"
23-
>#</a>
23+
>#</router-link>
2424
<slot />
2525
</component>
2626
</template>

src/mixins/scrollToElement.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default {
3535
*/
3636
async handleFocusAndScroll(hash) {
3737
const element = document.getElementById(hash);
38+
// if no element to focus or scroll, exit
3839
if (!element) return;
3940
// Focus scrolls to the element
4041
element.focus();

tests/unit/components/Asset.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ describe('Asset', () => {
185185
expect(asset.exists()).toBe(true);
186186
expect(asset.props()).toEqual({
187187
alt: image.alt,
188-
loading: "lazy",
188+
loading: 'lazy',
189189
variants: image.variants,
190190
});
191191
});
@@ -195,7 +195,7 @@ describe('Asset', () => {
195195
const asset = wrapper.find(ImageAsset);
196196
expect(asset.props()).toEqual({
197197
alt: image.alt,
198-
loading: "lazy",
198+
loading: 'lazy',
199199
variants: image.variants,
200200
});
201201
});

tests/unit/components/ContentNode/LinkableHeading.spec.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import { shallowMount } from '@vue/test-utils';
11+
import { shallowMount, RouterLinkStub } from '@vue/test-utils';
1212
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
1313

1414
describe('LinkableHeading', () => {
15+
const stubs = { 'router-link': RouterLinkStub };
16+
1517
it('renders a default section title that is a h2 by default', () => {
1618
const wrapper = shallowMount(LinkableHeading, {
19+
stubs,
1720
slots: { default: 'Title' },
1821
});
1922
expect(wrapper.text()).toBe('Title');
@@ -23,6 +26,7 @@ describe('LinkableHeading', () => {
2326

2427
it('renders a section title which heading is tag prop', () => {
2528
const wrapper = shallowMount(LinkableHeading, {
29+
stubs,
2630
propsData: {
2731
level: 3,
2832
},
@@ -32,6 +36,7 @@ describe('LinkableHeading', () => {
3236

3337
it('renders a section title with a header anchor and an id on the wrapper', async () => {
3438
const wrapper = shallowMount(LinkableHeading, {
39+
stubs,
3540
propsData: {
3641
anchor: 'title',
3742
},
@@ -41,7 +46,7 @@ describe('LinkableHeading', () => {
4146
expect(wrapper.text()).toBe('# Title');
4247
expect(wrapper.attributes('id')).toBe('title');
4348
const headerAnchor = wrapper.find('.header-anchor');
44-
expect(headerAnchor.attributes('href')).toBe('#title');
49+
expect(headerAnchor.props('to')).toEqual({ hash: '#title' });
4550
expect(headerAnchor.attributes('aria-label')).toBe('hidden');
4651
});
4752

@@ -52,6 +57,7 @@ describe('LinkableHeading', () => {
5257
document.body.appendChild(div);
5358

5459
const wrapper = shallowMount(LinkableHeading, {
60+
stubs,
5561
propsData: {
5662
anchor: 'title',
5763
},
@@ -60,7 +66,7 @@ describe('LinkableHeading', () => {
6066
expect(wrapper.text()).toBe('# Title');
6167
expect(wrapper.attributes('id')).not.toBe('title');
6268
const headerAnchor = wrapper.find('.header-anchor');
63-
expect(headerAnchor.attributes('href')).toBe('#title');
69+
expect(headerAnchor.props('to')).toEqual({ hash: '#title' });
6470
expect(headerAnchor.attributes('aria-label')).toBe('hidden');
6571
});
6672

@@ -71,6 +77,7 @@ describe('LinkableHeading', () => {
7177

7278
it('does not render anchor if target ide is true', () => {
7379
const wrapper = shallowMount(LinkableHeading, {
80+
stubs,
7481
propsData: {
7582
anchor: 'title',
7683
},

tests/unit/components/DocumentationTopic/PrimaryContent/PropertyTable.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe('PropertyTable', () => {
115115

116116
function mountComponent(options) {
117117
return mount(PropertyTable, {
118-
stubs: ['ContentNode'],
118+
stubs: ['ContentNode', 'router-link'],
119119
propsData,
120120
provide,
121121
...options,

tests/unit/components/DocumentationTopic/PrimaryContent/RestParameters.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('RestParameters', () => {
4848

4949
function mountComponent({ propsData: props, ...others } = {}) {
5050
return mount(RestParameters, {
51-
stubs: ['ContentNode'],
51+
stubs: ['ContentNode', 'router-link'],
5252
propsData: {
5353
...propsData,
5454
...props,

tests/unit/components/DocumentationTopic/PrimaryContent/RestResponses.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('RestResponses', () => {
5757

5858
function mountComponent(options) {
5959
const wrapper = mount(RestResponses, {
60-
stubs: ['ContentNode'],
60+
stubs: ['ContentNode', 'router-link'],
6161
propsData,
6262
provide,
6363
...options,

0 commit comments

Comments
 (0)