Skip to content

Commit

Permalink
fix(tab-bar): update to match MD design and remove transforms (#16348)
Browse files Browse the repository at this point in the history
Updates the tab-bar to match the MD bottom navigation spec: https://material.io/design/components/bottom-navigation.html#specs

Changes proposed in this pull request:
- moved flex properties to host, inherit in child anchor element
  - this allows the user to customize the tab-button flex properties & fixes #16231
- increased letter spacing
- removed transforms / transitions on active tab
- decreased badge size, add badge styling when empty for MD
- fix badge positioning on both iOS and MD
- updates e2e tests, adds a preview test for tab-bar
- updates documentation surrounding tabs

fixes #16231
fixes ionic-team/ionic-docs#175
fixes ionic-team/ionic-docs#163
  • Loading branch information
brandyscarney authored Nov 21, 2018
1 parent d336054 commit bc3e192
Show file tree
Hide file tree
Showing 18 changed files with 940 additions and 363 deletions.
21 changes: 1 addition & 20 deletions core/src/components/tab-bar/readme.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
# ion-tab-bar

Tab bar is the UI component that implements the array of button of `ion-tabs`. It's provided by default when `ion-tabs` is used, though, this "implicit" tab bar can not be customized.

In order to have a custom tab bar, it should be provided in user's markup as direct children of `ion-tabs`:

```html
<style>
ion-tab-bar {
font-size: 20px;
}
</style>

<ion-tabs>
<!-- User tabs -->
<ion-tab></ion-tab>
<ion-tab></ion-tab>

<!-- User provided ion-tab-bar that can be customized -->
<ion-tab-bar slot="bottom" color="dark" layout="icon-only">
</ion-tabs>
```
The tab bar is a UI component that contains a set of [tab buttons](../tab-button). A tab bar must be provided inside of [tabs](../tabs) to communicate with each [tab](../tab).


<!-- Auto Generated Below -->
Expand Down
12 changes: 5 additions & 7 deletions core/src/components/tab-bar/tab-bar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
* @prop --color: Color of the tab bar
*/

@include padding-horizontal(
var(--ion-safe-area-left),
var(--ion-safe-area-right)
);
@include padding-horizontal(var(--ion-safe-area-left), var(--ion-safe-area-right));

display: flex;

Expand All @@ -33,13 +30,14 @@
}

:host(.ion-color) {
--background: #{current-color(base)};
background: #{current-color(base)};
}

:host(.ion-color) ::slotted(ion-tab-button) {
--color: #{current-color(contrast, .7)};
--color-selected: #{current-color(contrast)};
--background-focused: #{current-color(shade)};
--color-selected: #{current-color(contrast)};;

color: #{current-color(contrast, .7)};
}

:host([slot="top"]) {
Expand Down
10 changes: 10 additions & 0 deletions core/src/components/tab-bar/test/preview/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { newE2EPage } from '@stencil/core/testing';

test('tab-bar: preview', async () => {
const page = await newE2EPage({
url: '/src/components/tab-bar/test/preview?ionic:_testing=true'
});

const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});
202 changes: 202 additions & 0 deletions core/src/components/tab-bar/test/preview/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<!DOCTYPE html>
<html dir="ltr">

<head>
<meta charset="UTF-8">
<title>Tab Bar - Preview</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<script src="../../../../../dist/ionic.js"></script>
<link rel="stylesheet" href="../../../../../css/ionic.bundle.css">
<link rel="stylesheet" href="../../../../../scripts/testing/styles.css">
</head>

<body>
<!-- Default -->
<ion-tab-bar selected-tab="1">

<ion-tab-button tab="1">
<ion-label>Recents</ion-label>
</ion-tab-button>

<ion-tab-button tab="2">
<ion-label>Favorites</ion-label>
<ion-badge>23</ion-badge>
</ion-tab-button>

<ion-tab-button tab="3">
<ion-label>Settings</ion-label>
</ion-tab-button>

</ion-tab-bar>

<!-- Badges -->
<ion-tab-bar selected-tab="1">
<ion-tab-button tab="1" layout="icon-top">
<ion-icon name="heart"></ion-icon>
<ion-label>Favorites</ion-label>
<ion-badge color="danger"></ion-badge>
</ion-tab-button>

<ion-tab-button tab="2">
<ion-icon name="musical-note"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="3">
<ion-icon name="today"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="4">
<ion-icon name="calendar"></ion-icon>
<ion-badge color="danger">47</ion-badge>
</ion-tab-button>
</ion-tab-bar>

<ion-tab-bar selected-tab="1">
<ion-tab-button tab="1">
<ion-icon name="musical-note"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="2" layout="icon-bottom">
<ion-icon name="heart"></ion-icon>
<ion-label>Favorites</ion-label>
</ion-tab-button>

<ion-tab-button tab="3">
<ion-icon name="today"></ion-icon>
<ion-badge color="danger">88</ion-badge>
</ion-tab-button>

<ion-tab-button tab="4">
<ion-icon name="calendar"></ion-icon>
</ion-tab-button>
</ion-tab-bar>

<ion-tab-bar selected-tab="1">
<ion-tab-button tab="1">
<ion-icon name="heart"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="2">
<ion-icon name="musical-note"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="3">
<ion-icon name="today"></ion-icon>
</ion-tab-button>
</ion-tab-bar>


<!-- Icons on top of text -->
<ion-tab-bar color="secondary" selected-tab="1">
<ion-tab-button tab="1">
<ion-label>Location</ion-label>
<ion-icon name="navigate"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="2">
<ion-badge color="danger">44</ion-badge>
<ion-icon name="heart"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="3">
<ion-label>Radio</ion-label>
<ion-icon name="musical-notes"></ion-icon>
</ion-tab-button>

</ion-tab-bar>


<!-- Icons below text -->
<ion-tab-bar color="dark" selected-tab="1">
<ion-tab-button tab="1" layout="icon-bottom">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="2" layout="icon-top">
<ion-badge>16</ion-badge>
<ion-label>Favorites</ion-label>
<ion-icon name="heart"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="3" layout="icon-bottom">
<ion-label>Settings</ion-label>
<ion-icon name="settings"></ion-icon>
</ion-tab-button>
</ion-tab-bar>


<!-- Icons right of text -->
<ion-tab-bar color="danger" selected-tab="1">
<ion-tab-button tab="1" layout="icon-end">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="2" layout="icon-end">
<ion-label>Favorites</ion-label>
<ion-icon name="heart"></ion-icon>
<ion-badge color="dark">33</ion-badge>
</ion-tab-button>

<ion-tab-button tab="3" layout="icon-end">
<ion-label>Settings</ion-label>
<ion-icon name="settings"></ion-icon>
</ion-tab-button>

</ion-tab-bar>


<!-- Icons left of text -->
<ion-tab-bar color="light" selected-tab="1">
<ion-tab-button tab="1" layout="icon-start">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
<ion-badge color="danger">12</ion-badge>
</ion-tab-button>

<ion-tab-button tab="2" layout="icon-start">
<ion-label>Favorites</ion-label>
<ion-icon name="heart"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="3" layout="icon-start">
<ion-label>Settings</ion-label>
<ion-icon name="settings"></ion-icon>
</ion-tab-button>

</ion-tab-bar>


<!-- No icons -->
<ion-tab-bar color="primary" selected-tab="1">
<ion-tab-button tab="1" layout="icon-hide">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="2" layout="icon-hide">
<ion-label>Favorites</ion-label>
<ion-icon name="heart"></ion-icon>
</ion-tab-button>

<ion-tab-button tab="3" layout="icon-hide">
<ion-label>Settings</ion-label>
<ion-icon name="settings"></ion-icon>
<ion-badge color="danger">2</ion-badge>
</ion-tab-button>
</ion-tab-bar>

<style>
body {
background: #f6f6f6;
}

ion-tab-bar {
margin-bottom: 10px;
}

</style>
</body>

</html>
Loading

0 comments on commit bc3e192

Please sign in to comment.