-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8fb7e2
commit 4ba4509
Showing
6 changed files
with
163 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[ | ||
{ | ||
"name": "Tab 1", | ||
"selected": true, | ||
"paragraph": "Toe in voluptate velit esse cillum dolore eu fugiat nulla pariatur.", | ||
"button": "Alpaca button" | ||
}, | ||
{ | ||
|
||
"name": "Tab 2", | ||
"selected": false, | ||
"paragraph": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.", | ||
"button": "" | ||
}, | ||
{ | ||
"name": "Tab 3", | ||
"selected": false, | ||
"paragraph": "Sed do eiusmod tempor incididunt ut labo. Ut enim ad minim veniam, re et dolore magna aliqua. quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.", | ||
"button": "" | ||
}, | ||
{ | ||
"name": "Tab 4", | ||
"selected": false, | ||
"paragraph": "Toe in voluptate velit esse cillum dolore eu fugiat nulla pariatur.", | ||
"button": "" | ||
}, | ||
{ | ||
"name": "Tab 5", | ||
"selected": false, | ||
"paragraph": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.", | ||
"button": "" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,41 @@ | ||
import { mount } from '@vue/test-utils' | ||
import { shallowMount } from '@vue/test-utils' | ||
import ATab from './Tab.vue' | ||
|
||
const factory = () => { | ||
const defaultData = { | ||
slots: { | ||
default: '<span>Tab default text</span>' | ||
}, | ||
propsData: { | ||
name: 'Tab' | ||
} | ||
} | ||
|
||
return shallowMount(ATab, defaultData) | ||
} | ||
|
||
describe('Tab', () => { | ||
it('has default structure', () => { | ||
const wrapper = mount(ATab, { | ||
propsData: { | ||
name: 'Tab' | ||
} | ||
}) | ||
const wrapper = factory() | ||
|
||
expect(wrapper).toBe('DIV') | ||
expect(wrapper.attributes().role).toBeDefined() | ||
expect(wrapper.attributes().role).toEqual('tabpanel') | ||
expect(wrapper.attributes().role).toEqual('tab') | ||
expect(wrapper.attributes('data-tab')).toBeDefined() | ||
}) | ||
|
||
it('renders slot text when passed', () => { | ||
const wrapper = mount(ATab, { | ||
slots: { | ||
default: '<span>Tab default text</span>' | ||
}, | ||
propsData: { | ||
name: 'Tab' | ||
} | ||
}) | ||
const wrapper = factory() | ||
|
||
expect(wrapper.find('div > span').exists()).toBe(true) | ||
expect(wrapper.find('div > span').text()).toEqual('Tab default text') | ||
}) | ||
|
||
it('has correct id attribute', () => { | ||
const wrapper = mount(ATab, { | ||
propsData: { | ||
name: 'Sample' | ||
} | ||
}) | ||
const wrapper = factory() | ||
|
||
expect(wrapper.props().name).toBe('Sample') | ||
expect(wrapper.props().name).toBe('Tab') | ||
expect(wrapper.attributes().id).toBeDefined() | ||
expect(wrapper.attributes().id).toEqual('sample-tab') | ||
expect(wrapper.attributes().id).toEqual('tab-tab') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
<div | ||
role="tablist" | ||
:class="getClass('tabs')" | ||
> | ||
<button | ||
v-for="(tab, i) in tabs" | ||
:key="`${tab.id}-tab-trigger`" | ||
:id="`${tab.id}-tab-trigger`" | ||
:aria-controls="`${tab.id}-tab`" | ||
:aria-selected="tab.isActive || 'false'" | ||
:aria-expanded="tab.isActive || 'false'" | ||
type="button" | ||
role="tab" | ||
:ref="`button_${i}`" | ||
:class="getClass(tab.isActive ? 'tabs__nav-button--active' : 'tabs__nav-button')"" | ||
@click="selectTab(tab)" | ||
@keydown="onKeydown" | ||
<div :class="getClass('tabs')"> | ||
<div | ||
role="tablist" | ||
:class="getClass('tabs__tablist')" | ||
> | ||
<!-- @slot Custom tab button content (Scoped slot) --> | ||
<slot | ||
name="button" | ||
:tab="tab" | ||
<button | ||
v-for="(tab, i) in tabs" | ||
:key="`${tab.id}-tab-trigger`" | ||
:id="`${tab.id}-tab-trigger`" | ||
:aria-controls="`${tab.id}-tab`" | ||
:aria-selected="`${tab.isActive}`" | ||
:aria-expanded="`${tab.isActive}`" | ||
type="button" | ||
role="tab" | ||
:ref="`button_${i}`" | ||
:class="[ | ||
getClass('tabs__nav-button'), | ||
tab.isActive ? getClass('tabs__nav-button--active') : getClass('tabs__nav-button--inactive') | ||
]" | ||
:tabindex="!tab.isActive && -1" | ||
@click="selectTab(tab)" | ||
@keydown="onKeydown" | ||
> | ||
{{ tab.name }} | ||
</slot> | ||
<!-- @slot Custom accordion tab icon (Named slot) --> | ||
<slot name="icon"> | ||
|
||
</slot> | ||
</button> | ||
<!-- @slot Custom tab button content (Scoped slot) --> | ||
<slot | ||
name="button" | ||
:tab="tab" | ||
> | ||
{{ tab.name }} | ||
</slot> | ||
</button> | ||
</div> | ||
<div | ||
ref="content" | ||
class="a-tabs__content" | ||
:class="getClass('tabs__content')" | ||
tabindex="-1" | ||
tabindex="0" | ||
> | ||
<!-- @slot Tab components --> | ||
<slot/> | ||
<slot /> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.