Skip to content

Commit

Permalink
[IMPROVE] Update tabs markup (#14964)
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan authored and ggazzo committed Jul 11, 2019
1 parent ef62371 commit 564d5d5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
17 changes: 15 additions & 2 deletions app/theme/client/imports/components/tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
}

.tab {
display: flex;

margin: 0 1rem;
padding: 1rem 0;

cursor: pointer;

Expand All @@ -24,13 +25,25 @@

border-bottom: 2px solid transparent;

font-family: inherit;
font-size: 1rem;

font-weight: 500;
line-height: 1.25rem;
align-items: stretch;
flex-flow: row nowrap;

&.active {
color: var(--rc-color-button-primary);
border-bottom-color: var(--rc-color-button-primary);
}

&:focus {
text-decoration: underline;
}

& > span {
flex: 1;

padding: 1rem 0;
}
}
13 changes: 10 additions & 3 deletions app/ui/client/components/tabs.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<template name="tabs">
<div class="tabs">
<div class="tabs-wrapper">
{{#each tabs}}
<div class="tab {{#if isActive value}}active{{/if}}" data-value={{value}}>{{label}}</div>
<div class="tabs-wrapper" role="tablist">
{{#each tab in tabs}}
<button
class="tab {{#if isActive tab.value}}active{{/if}}"
data-value={{tab.value}}
{{ariaSelected tab.value}}
role="tab"
>
<span tabindex="-1">{{tab.label}}</span>
</button>
{{/each}}
</div>
</div>
Expand Down
16 changes: 11 additions & 5 deletions app/ui/client/components/tabs.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { ReactiveVar } from 'meteor/reactive-var';
import { Template } from 'meteor/templating';

import './tabs.html';


Template.tabs.onCreated(function() {
this.activeTab = new ReactiveVar(this.data.tabs.tabs.find((tab) => tab.active).value);
});

Template.tabs.events({
'click .tab'(e) {
const { value } = e.currentTarget.dataset;
if (value === Template.instance().activeTab.get()) {
'click .tab'(event, instance) {
const { value } = event.currentTarget.dataset;
if (value === instance.activeTab.get()) {
return;
}
Template.instance().activeTab.set(value);
Template.instance().data.tabs.onChange(value);
instance.activeTab.set(value);
instance.data.tabs.onChange(value);
},
});

Expand All @@ -23,4 +26,7 @@ Template.tabs.helpers({
isActive(value) {
return Template.instance().activeTab.get() === value;
},
ariaSelected(value) {
return Template.instance().activeTab.get() === value ? { 'aria-selected': 'true' } : {};
},
});
1 change: 0 additions & 1 deletion app/ui/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import './views/app/photoswipe';
import './components/icon';
import './components/table.html';
import './components/table';
import './components/tabs.html';
import './components/tabs';
import './components/popupList.html';
import './components/popupList';
Expand Down

0 comments on commit 564d5d5

Please sign in to comment.