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

fix(v-tab): anchor hash routing #5124

Merged
merged 1 commit into from Oct 6, 2018
Merged

fix(v-tab): anchor hash routing #5124

merged 1 commit into from Oct 6, 2018

Conversation

amritk
Copy link
Contributor

@amritk amritk commented Sep 19, 2018

Description

Just a minor fix for the href attribute on v-tab when using hash urls. Originally it prevents default, but I believe that the intention was to only prevent default when the url is exactly '#'. In the case of using hash urls for the tab, this will not work.

Motivation and Context

I had this issue open for a while to see why this code was here in the first place, after no feedback decided to fix it as I am going live with a feature that is using this soon.
#4784

How Has This Been Tested?

I have tested that it works visually in my project, not quite sure how to write a test for this one.

Markup:

<template lang="pug">
.main
    v-tabs.shadow(v-model="activeTab" slider-color="primary" fixed-tabs)
        v-tab(v-for="tab in tabs" :key="tab.name" :href="`#${tab.name}`")
            | {{ $t(tab.title) }}
        v-tab-item(id="teams")
            | These are the teams
        v-tab-item(id="players")
            | These are the players
        v-tab-item(id="matches")
            | These are the matches
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import * as VTabs from 'vuetify/es5/components/VTabs'

@Component({
    components: {
        ...VTabs
    }
})
export default class TeamFinderList extends Vue {
    activeTab: string = null
    tabs = [
        {
            name: 'teams',
            title: 'Teams'
        },
        {
            name: 'players',
            title: 'Players'
        },
        {
            name: 'matches',
            title: 'Matches'
        }
    ]

    created () {
        // Load the correct tab in the beinning
        this.activeTab = this.$route.hash.substr(1)
    }
}
</script>

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Improvement/refactoring (non-breaking change that doesn't add any feature but make things better)

Checklist:

  • The PR title is no longer than 64 characters.
  • The PR is submitted to the correct branch (master for bug fixes, dev for new features and breaking changes).
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have created a PR in the documentation with the necessary changes.

@johnleider
Copy link
Member

Tabs are about to be updated for v1.3, I'll revisit this once I move to that component in a few days.

@amritk
Copy link
Contributor Author

amritk commented Sep 25, 2018

sounds good

@egeersoz
Copy link

egeersoz commented Oct 6, 2018

Is this still slated for 1.3.0? A critical part of my app requires switching tabs using the URL.

@johnleider johnleider merged commit fcf51f1 into vuetifyjs:master Oct 6, 2018
@KaelWD
Copy link
Member

KaelWD commented Oct 10, 2018

This doesn't fix anything: you still can't link directly to a tab by its hash, and clicking a tab scrolls the page to the top of the tab item (https://vuetifyjs.com/en/components/alerts#props)

@amritk
Copy link
Contributor Author

amritk commented Oct 10, 2018

@KaelWD I had a working example. Let me try out the fix tomorrow and I'll see if it still works.

lzhoucs added a commit to lzhoucs/vuetify that referenced this pull request Oct 10, 2018
* Filter comments to count actual rendered elements

* Remove unnecesary conditional

* Filter out VNodes with empty text

* fix(VImg): allow transition to be disabled

* fix(v-combobox): update onEnterDown logic

should let v-select-list handle the update if user is selecting index

fixes vuetifyjs#5008

* fix(v-slider): remove duplicate change event

onMouseUp is already triggered by v-input, our mouseUp usage is more internal for slider, just
renamed method

fixes vuetifyjs#4996

* fix(v-combobox): prevent default action

when using a combobox, enter should be treated differently and not invoke a form submit

fixes vuetifyjs#4974

* fix(VMenu): make detached provide reactive

fixes vuetifyjs#5010

* fix(VBreadcrumbs): add Themeable classes

fixes vuetifyjs#4986

* Fix vuetifyjs#3904: dividers are not shown in dynamic vertical stepper (vuetifyjs#4767)

* Fix vuetifyjs#4696: Checkbox is hard to click with ripple disabled (vuetifyjs#4776)

* test(v-stepper-ccontent): add provide

* [release] 1.2.2

* V-Autocomplete: hide-no-data also controls opening menu upon item update

fixes vuetifyjs#4663

* fix(v-footer): fix applicationProperty update

add new value for inset footer to applicationable

fixes vuetifyjs#4686

* [release] 1.1.16

* [release] 1.2.3

* fix(VMenu): inherit light/dark from v-app

playground: https://pastebin.com/raw/jtLrtVtP

* fix(DatePicker): Title spacing when month === August (vuetifyjs#5027)

* fix(v-autocomplete): add conditional for single-line

fixes vuetifyjs#5076

* fix(v-list-tile-action): add support for v-html

fixes vuetifyjs#5037

* fix(v-navigation-drawer): pull in Dependent mixin for click-outside

* feat(v-carousel): convert to ts

* refactor(v-carousel): update review items

* chore(v-carousel): update type

* refactor(v-carousel): update feedback items

* feat(dependent): convert to ts

* feat(filterable): convert to ts

* feat(returnable): convert to ts

* feat(components-index): convert to ts

* feat(colorable): convert to ts

* refactor(colors.d.ts): move file

* fix(translatable): partially revert 5f661a3

reverted back to original logic to correct scrolling bug

fixes vuetifyjs#4847

* [release] 1.2.4

* style(v-pagination): button cutting the page number

When props:length is a very large number,
the number of the button protrudes.

# <type>: (If applied, this commit will...) <subject> (Max 50 char)
# |<----  Using a Maximum Of 50 Characters  ---->| Hard limit to 72 -->|

# Explain why this change is being made
# |<----   Try To Limit Each Line to a Maximum Of 72 Characters   ---->|

# Provide links to any relevant issues, articles, commits, or other
# pull requests
# Example: See #23, fixes vuetifyjs#58

# --- COMMIT END ---
# <type> can be
#    feat     (new feature)
#    fix      (bug fix)
#    refactor (refactoring production code)
#    style    (formatting, missing semi colons, etc; no code change)
#    test     (adding or refactoring tests; no production code change)
#    chore    (updating npm scripts etc; no production code change)
# --------------------
# Remember to
#    Capitalize the subject line
#    Use the imperative mood in the subject line
#    Do not end the subject line with a period
#    Separate subject from body with a blank line (comments don't count)
#    Use the body to explain what and why vs. how
#    Can use multiple lines with "-" for bullet points in body
#
# If you can't summarize your changes in a single line, they should
# probably be split into multiple commits
# --------------------
# For more information about this template, check out
# https://gist.github.com/adeekshith/cd4c95a064977cdc6c50

* fix(iterable): rows-per-page selector not inheriting theme

* [release] 1.2.5

* fix(VStepperStep): use colorable mixin

fixes vuetifyjs#5183

* test for vuetifyjs#5183

* Fix vuetifyjs#4760: show next pagination page if current page is last

* [release] 1.2.6

* fix(v-radio): remove bottom margin

if only or last child, do not add margin

fixes vuetifyjs#5162

* fix(v-autocomplete): allow setSearch for numeric 0

fixes vuetifyjs#5110

* [v-tab] Fix anchor hash routing (vuetifyjs#5124)

* fix(v-messages): change assigned key

fixes vuetifyjs#4880

* fix(v-select): remove change event for external changes

fixes vuetifyjs#5006

* fix(v-text-field): change mouseup focus to conditional

should only focus the input if the originating mousedown was on the element

fixes vuetifyjs#5018

* fix(VLinearProgress): invalid class applied when using css color

* fix(VEditDialog): apply theme classes to content (vuetifyjs#5152)

* fix(VEditDialog): apply theme classes to content

fixes vuetifyjs#5127

* test: update snapshots

* [release] 1.2.7

* Update snapshots after merge.
lzhoucs added a commit to lzhoucs/vuetify that referenced this pull request Oct 10, 2018
* Filter comments to count actual rendered elements

* Remove unnecesary conditional

* Filter out VNodes with empty text

* fix(VImg): allow transition to be disabled

* fix(v-combobox): update onEnterDown logic

should let v-select-list handle the update if user is selecting index

fixes vuetifyjs#5008

* fix(v-slider): remove duplicate change event

onMouseUp is already triggered by v-input, our mouseUp usage is more internal for slider, just
renamed method

fixes vuetifyjs#4996

* fix(v-combobox): prevent default action

when using a combobox, enter should be treated differently and not invoke a form submit

fixes vuetifyjs#4974

* fix(VMenu): make detached provide reactive

fixes vuetifyjs#5010

* fix(VBreadcrumbs): add Themeable classes

fixes vuetifyjs#4986

* Fix vuetifyjs#3904: dividers are not shown in dynamic vertical stepper (vuetifyjs#4767)

* Fix vuetifyjs#4696: Checkbox is hard to click with ripple disabled (vuetifyjs#4776)

* test(v-stepper-ccontent): add provide

* [release] 1.2.2

* V-Autocomplete: hide-no-data also controls opening menu upon item update

fixes vuetifyjs#4663

* fix(v-footer): fix applicationProperty update

add new value for inset footer to applicationable

fixes vuetifyjs#4686

* [release] 1.1.16

* [release] 1.2.3

* fix(VMenu): inherit light/dark from v-app

playground: https://pastebin.com/raw/jtLrtVtP

* fix(DatePicker): Title spacing when month === August (vuetifyjs#5027)

* fix(v-autocomplete): add conditional for single-line

fixes vuetifyjs#5076

* fix(v-list-tile-action): add support for v-html

fixes vuetifyjs#5037

* fix(v-navigation-drawer): pull in Dependent mixin for click-outside

* feat(v-carousel): convert to ts

* refactor(v-carousel): update review items

* chore(v-carousel): update type

* refactor(v-carousel): update feedback items

* feat(dependent): convert to ts

* feat(filterable): convert to ts

* feat(returnable): convert to ts

* feat(components-index): convert to ts

* feat(colorable): convert to ts

* refactor(colors.d.ts): move file

* fix(translatable): partially revert 5f661a3

reverted back to original logic to correct scrolling bug

fixes vuetifyjs#4847

* [release] 1.2.4

* style(v-pagination): button cutting the page number

When props:length is a very large number,
the number of the button protrudes.

# <type>: (If applied, this commit will...) <subject> (Max 50 char)
# |<----  Using a Maximum Of 50 Characters  ---->| Hard limit to 72 -->|

# Explain why this change is being made
# |<----   Try To Limit Each Line to a Maximum Of 72 Characters   ---->|

# Provide links to any relevant issues, articles, commits, or other
# pull requests
# Example: See #23, fixes vuetifyjs#58

# --- COMMIT END ---
# <type> can be
#    feat     (new feature)
#    fix      (bug fix)
#    refactor (refactoring production code)
#    style    (formatting, missing semi colons, etc; no code change)
#    test     (adding or refactoring tests; no production code change)
#    chore    (updating npm scripts etc; no production code change)
# --------------------
# Remember to
#    Capitalize the subject line
#    Use the imperative mood in the subject line
#    Do not end the subject line with a period
#    Separate subject from body with a blank line (comments don't count)
#    Use the body to explain what and why vs. how
#    Can use multiple lines with "-" for bullet points in body
#
# If you can't summarize your changes in a single line, they should
# probably be split into multiple commits
# --------------------
# For more information about this template, check out
# https://gist.github.com/adeekshith/cd4c95a064977cdc6c50

* fix(iterable): rows-per-page selector not inheriting theme

* [release] 1.2.5

* fix(VStepperStep): use colorable mixin

fixes vuetifyjs#5183

* test for vuetifyjs#5183

* Fix vuetifyjs#4760: show next pagination page if current page is last

* [release] 1.2.6

* fix(v-radio): remove bottom margin

if only or last child, do not add margin

fixes vuetifyjs#5162

* fix(v-autocomplete): allow setSearch for numeric 0

fixes vuetifyjs#5110

* [v-tab] Fix anchor hash routing (vuetifyjs#5124)

* fix(v-messages): change assigned key

fixes vuetifyjs#4880

* fix(v-select): remove change event for external changes

fixes vuetifyjs#5006

* fix(v-text-field): change mouseup focus to conditional

should only focus the input if the originating mousedown was on the element

fixes vuetifyjs#5018

* fix(VLinearProgress): invalid class applied when using css color

* fix(VEditDialog): apply theme classes to content (vuetifyjs#5152)

* fix(VEditDialog): apply theme classes to content

fixes vuetifyjs#5127

* test: update snapshots

* [release] 1.2.7

* fix(v-ripple): decrease click target size on selection control ripple (vuetifyjs#5250)

hopefully removes instances where click targets overlap between adjacent inputs

closes vuetifyjs#2661

* fix(v-stepper): add registrable mixin

fixes vuetifyjs#3330

* fix(v-select): change isDisabled conditional

should use regular text color when readonly

fixes vuetifyjs#5051

* fix(v-dialog): always remove scrollbar when fullscreen

fixes vuetifyjs#3101

* fix(v-ripple): only modify position if current one is static (vuetifyjs#5249)

* fix(v-ripple): only modify position if current one is static

solves problems when using for example position sticky

closes vuetifyjs#2573

* chore(ripple): ignore eslint for max-statements

* [release] 1.2.8
@amritk
Copy link
Contributor Author

amritk commented Oct 10, 2018

@KaelWD This fix was to set the hash fragment in the url, which it correctly does now. Not sure why the scrolling is happening. To set it initially, on mounted you can do something like this:

this.activeTab = this.$route.hash.substr(1)

Not sure if we want to include this as part of the tabs component.

Actually that is probably why this code was in here in the first place, to prevent the scrolling in the docs. Maybe we should keep the routing but prevent the scroll.

I threw up a working example here:
https://hockeycommunity.com/explore/amrit

<template lang="pug">
    v-tabs(v-model="activeTab" slider-color="primary" fixed-tabs)
        v-tab(v-for="tab in tabs" :key="tab" :href="`#${tab}`")
            | {{ tab }}
        v-tab-item(:id="tab" v-for="tab in tabs" :key="tab")
            | This is the {{ tab }} feed
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import * as VTabs from 'vuetify/es5/components/VTabs'

@Component({
    components: {
        ...VTabs
    }
})
export default class Amrit extends Vue {
    activeTab: string = null
    tabs = ['teams', 'players', 'matches']

    mounted () {
        const tab = this.$route.hash.substr(1) || 'teams'
        this.activeTab = tab
    }
}
</script>

@amritk
Copy link
Contributor Author

amritk commented Oct 10, 2018

I just realized if you use router-link instead of an achor it works much better, including linking directly to the tab

<template lang="pug">
    v-tabs(v-model="activeTab" slider-color="primary" fixed-tabs)
        v-tab(v-for="tab in tabs" :key="tab" :to="`#${tab}`")
            | {{ tab }}
        v-tab-item(:id="tab" v-for="tab in tabs" :key="tab")
            | This is the {{ tab }} feed
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import * as VTabs from 'vuetify/es5/components/VTabs'

@Component({
    components: {
        ...VTabs
    }
})
export default class Amrit extends Vue {
    activeTab: string = null
    tabs = ['teams', 'players', 'matches']
}
</script>

@KaelWD
Copy link
Member

KaelWD commented Oct 11, 2018

Correct. You could've also set the hash yourself with a watcher on activeTab, seeing as you're already doing this.activeTab = this.$route.hash.substr(1) in userland.

@amritk
Copy link
Contributor Author

amritk commented Oct 11, 2018

Yes that is what I was doing while I was waiting for the pull request. But the tabs component should be handling that.

@lock
Copy link

lock bot commented Apr 15, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please direct any non-bug questions to our Discord

@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants