Skip to content
This repository has been archived by the owner on Oct 24, 2018. It is now read-only.

Fix bug which causes tab <section>s to have a leading # before id att… #50

Merged
merged 2 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to `vue-tabs-component` will be documented in this file
- Added `defaultTabHash` option
- Fixed bug #32 `changed` event fires twice on each change
- Added `clicked` event, fires when active tab is clicked
- Fixed a bug which caused sections within tabs to have a '#' included in their id attribute.

## 1.4.0 - 2017-11-06
- Added `isDisabled` prop to `Tab`
Expand Down
14 changes: 7 additions & 7 deletions __tests__/__snapshots__/tabs.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

exports[`vue-tabs-component can accept a prefix and a suffix for the name 1`] = `
"
<div id=\\"app\\"><div class=\\"tabs-component\\"><ul role=\\"tablist\\" class=\\"tabs-component-tabs\\"><li role=\\"presentation\\" class=\\"tabs-component-tab is-active\\"><a aria-controls=\\"#first-tab\\" aria-selected=\\"true\\" href=\\"#first-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">prefixFirst tabsuffix</a></li></ul> <div class=\\"tabs-component-panels\\"><section id=\\"#first-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"\\">
<div id=\\"app\\"><div class=\\"tabs-component\\"><ul role=\\"tablist\\" class=\\"tabs-component-tabs\\"><li role=\\"presentation\\" class=\\"tabs-component-tab is-active\\"><a aria-controls=\\"#first-tab\\" aria-selected=\\"true\\" href=\\"#first-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">prefixFirst tabsuffix</a></li></ul> <div class=\\"tabs-component-panels\\"><section id=\\"first-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"\\">
First tab content
</section></div></div></div>
"
`;

exports[`vue-tabs-component can mount tabs 1`] = `
"
<div id=\\"app\\"><div class=\\"tabs-component\\"><ul role=\\"tablist\\" class=\\"tabs-component-tabs\\"><li role=\\"presentation\\" class=\\"tabs-component-tab is-active\\"><a aria-controls=\\"#first-tab\\" aria-selected=\\"true\\" href=\\"#first-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">First tab</a></li><li role=\\"presentation\\" class=\\"tabs-component-tab\\"><a aria-controls=\\"#second-tab\\" href=\\"#second-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">Second tab</a></li><li role=\\"presentation\\" class=\\"tabs-component-tab\\"><a aria-controls=\\"#third-tab\\" href=\\"#third-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">Third tab</a></li></ul> <div class=\\"tabs-component-panels\\"><section id=\\"#first-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"\\">
<div id=\\"app\\"><div class=\\"tabs-component\\"><ul role=\\"tablist\\" class=\\"tabs-component-tabs\\"><li role=\\"presentation\\" class=\\"tabs-component-tab is-active\\"><a aria-controls=\\"#first-tab\\" aria-selected=\\"true\\" href=\\"#first-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">First tab</a></li><li role=\\"presentation\\" class=\\"tabs-component-tab\\"><a aria-controls=\\"#second-tab\\" href=\\"#second-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">Second tab</a></li><li role=\\"presentation\\" class=\\"tabs-component-tab\\"><a aria-controls=\\"#third-tab\\" href=\\"#third-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">Third tab</a></li></ul> <div class=\\"tabs-component-panels\\"><section id=\\"first-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"\\">
First tab content
</section> <section aria-hidden=\\"true\\" id=\\"#second-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"display: none;\\">
</section> <section aria-hidden=\\"true\\" id=\\"second-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"display: none;\\">
Second tab content
</section> <section aria-hidden=\\"true\\" id=\\"#third-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"display: none;\\">
</section> <section aria-hidden=\\"true\\" id=\\"third-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"display: none;\\">
Third tab content
</section></div></div></div>
"
Expand All @@ -28,11 +28,11 @@ Object {

exports[`vue-tabs-component uses the fragment of the url to determine which tab to open 1`] = `
"
<div id=\\"app\\"><div class=\\"tabs-component\\"><ul role=\\"tablist\\" class=\\"tabs-component-tabs\\"><li role=\\"presentation\\" class=\\"tabs-component-tab\\"><a aria-controls=\\"#first-tab\\" href=\\"#first-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">First tab</a></li><li role=\\"presentation\\" class=\\"tabs-component-tab is-active\\"><a aria-controls=\\"#second-tab\\" aria-selected=\\"true\\" href=\\"#second-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">Second tab</a></li><li role=\\"presentation\\" class=\\"tabs-component-tab\\"><a aria-controls=\\"#third-tab\\" href=\\"#third-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">Third tab</a></li></ul> <div class=\\"tabs-component-panels\\"><section aria-hidden=\\"true\\" id=\\"#first-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"display: none;\\">
<div id=\\"app\\"><div class=\\"tabs-component\\"><ul role=\\"tablist\\" class=\\"tabs-component-tabs\\"><li role=\\"presentation\\" class=\\"tabs-component-tab\\"><a aria-controls=\\"#first-tab\\" href=\\"#first-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">First tab</a></li><li role=\\"presentation\\" class=\\"tabs-component-tab is-active\\"><a aria-controls=\\"#second-tab\\" aria-selected=\\"true\\" href=\\"#second-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">Second tab</a></li><li role=\\"presentation\\" class=\\"tabs-component-tab\\"><a aria-controls=\\"#third-tab\\" href=\\"#third-tab\\" role=\\"tab\\" class=\\"tabs-component-tab-a\\">Third tab</a></li></ul> <div class=\\"tabs-component-panels\\"><section aria-hidden=\\"true\\" id=\\"first-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"display: none;\\">
First tab content
</section> <section id=\\"#second-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"\\">
</section> <section id=\\"second-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"\\">
Second tab content
</section> <section aria-hidden=\\"true\\" id=\\"#third-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"display: none;\\">
</section> <section aria-hidden=\\"true\\" id=\\"third-tab\\" role=\\"tabpanel\\" class=\\"tabs-component-panel\\" style=\\"display: none;\\">
Third tab content
</section></div></div></div>
"
Expand Down
10 changes: 6 additions & 4 deletions src/components/Tab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<section v-show="isActive"
:aria-hidden="! isActive"
class="tabs-component-panel"
:id="hash"
:id="computedId"
role="tabpanel"
>
<slot />
Expand All @@ -29,14 +29,16 @@
return this.prefix + this.name + this.suffix;
},

computedId() {
return this.id ? this.id : this.name.toLowerCase().replace(/ /g, '-');
},

hash() {
if (this.isDisabled) {
return '#';
}

return this.id ?
'#' + this.id :
'#' + this.name.toLowerCase().replace(/ /g, '-');
return '#' + this.computedId;
},
},
};
Expand Down