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

[IMPROVE] Update tabs markup #14964

Merged
merged 1 commit into from
Jul 11, 2019
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
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 @@ -48,7 +48,6 @@ import './components/icon.html';
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