Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit f18fda1

Browse files
author
Matt Goo
authored
fix(tab): update readme and ref name in tab component (#226)
1 parent fedf138 commit f18fda1

File tree

6 files changed

+44
-52
lines changed

6 files changed

+44
-52
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ matrix:
3737
- docker pull mdcreact/screenshots
3838
- docker image ls
3939
script:
40-
- docker run -it --rm --cap-add=SYS_ADMIN -e MDC_GCLOUD_SERVICE_ACCOUNT_KEY="${MDC_GCLOUD_SERVICE_ACCOUNT_KEY}" mdcreact/screenshots /bin/sh -c "git fetch; git checkout \"${CURRENT_BRANCH}\"; git pull; npm i; /home/pptruser/material-components-web-react/test/screenshot/start.sh; sleep 300s; npm run test:image-diff"
40+
- docker run -it --rm --cap-add=SYS_ADMIN -e MDC_GCLOUD_SERVICE_ACCOUNT_KEY="${MDC_GCLOUD_SERVICE_ACCOUNT_KEY}" mdcreact/screenshots /bin/sh -c "git fetch; git checkout \"${CURRENT_BRANCH}\"; git pull; npm i; /home/pptruser/material-components-web-react/test/screenshot/start.sh; sleep 330s; npm run test:image-diff"

package-lock.json

Lines changed: 28 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
"line-ripple",
3535
"ripple",
3636
"top-app-bar",
37+
"tab",
38+
"tab-scroller",
3739
"infrastructure",
3840
"tab-indicator",
3941
"text-field"

packages/tab/README.md

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ class MyApp extends React.Component {
3636

3737
render() {
3838
return (
39-
<Tab
40-
active={this.state.active}
41-
// this will be another tab's clientRect object
42-
previousActiveClientRect={previousTabClientRect}
43-
>
39+
<Tab active={this.state.active}>
4440
<MaterialIcon className='mdc-tab__icon' icon='favorite' />
4541
<span className='mdc-tab__text-label'>Love</span>
4642
</Tab>
@@ -51,7 +47,7 @@ class MyApp extends React.Component {
5147

5248
#### With Custom Indicator
5349

54-
Possibly you don't want to use the default underline indicator, but instead would like to use an icon. You'll need to add an `indicator` prop, which is a function that returns a `<TabIndicator />` element.
50+
Possibly you don't want to use the default underline indicator, but instead would like to use an icon. You'll need to add an `indicatorContent` prop, which should be set to an icon element.
5551

5652
```js
5753
import React from 'react';
@@ -65,32 +61,12 @@ class MyApp extends React.Component {
6561
return (
6662
<Tab
6763
active={this.state.active}
68-
previousActiveClientRect={previousTabClientRect}
69-
indicator={this.renderIndicator}
64+
indicatorContent={<MaterialIcon icon='favorite' />}
7065
>
7166
<span className='mdc-tab__text-label'>Love</span>
7267
</Tab>
7368
);
7469
}
75-
76-
renderIndicator(props) {
77-
// must return a <TabIndicator /> element
78-
return (
79-
<TabIndicator
80-
icon
81-
{/*--
82-
You need to pass
83-
active, ref, and previousIndicatorClientRect props to the
84-
TabIndicator element
85-
--*/}
86-
active={props.active}
87-
ref={props.ref}
88-
previousIndicatorClientRect={props.previousIndicatorClientRect}
89-
>
90-
<MaterialIcon icon='favorite' />
91-
</TabIndicator>
92-
);
93-
}
9470
}
9571
```
9672

@@ -101,9 +77,10 @@ Prop Name | Type | Description
10177
active | boolean | If true will activate the tab and indicator.
10278
className | string | Classes to appear on className attribute of root element.
10379
isFadingIndicator | boolean | Enables a fading indicator, instead of sliding (default).
104-
indicator | function | Function that is passed props as an argument, that must return a `<TabIndicator />` element. The `<TabIndicator />` element must be passed `active`, `ref`, and `previousIndicatorClientRect` props. See example above.
80+
indicatorContent | element | Element that will appear within the `<TabIndicator />` element.
10581
minWidth | boolean | If true will display the `<Tab />` as narrow as possible.
10682
isMinWidthIndicator | boolean | If true will display the `<TabIndicator />` to the size of the longest content element.
83+
isIconIndicator | boolean | If true will display the indicator content in the center of the tab.
10784
previousIndicatorClientRect | ClientRect | The indicator's clientRect that was previously activated.
10885
onTransitionEnd | function | transitionend event callback handler.
10986

packages/tab/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default class Tab extends Component {
99
foundation_ = null;
1010
tabElement_ = React.createRef();
1111
tabContentElement_ = React.createRef();
12-
tabIndicatorElement_ = React.createRef();
12+
tabIndicator_ = React.createRef();
1313

1414
state = {
1515
'classList': new Set(),
@@ -77,8 +77,8 @@ export default class Tab extends Component {
7777
}
7878

7979
computeIndicatorClientRect = () => {
80-
if (!this.tabIndicatorElement_.current) return;
81-
return this.tabIndicatorElement_.current.computeContentClientRect();
80+
if (!this.tabIndicator_.current) return;
81+
return this.tabIndicator_.current.computeContentClientRect();
8282
}
8383

8484
computeDimensions = () => {
@@ -143,7 +143,7 @@ export default class Tab extends Component {
143143
icon={isIconIndicator}
144144
active={active}
145145
fade={isFadingIndicator}
146-
ref={this.tabIndicatorElement_}
146+
ref={this.tabIndicator_}
147147
previousIndicatorClientRect={previousActiveClientRect}
148148
>
149149
{indicatorContent}

test/unit/tab/index.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ test('#adapter.focus focuses the tabElement_', () => {
123123
td.verify(wrapper.instance().tabElement_.current.focus(), {times: 1});
124124
});
125125

126-
test('#computeIndicatorClientRect returns the tabIndicatorElement_ clientRect', () => {
126+
test('#computeIndicatorClientRect returns the tabIndicator_ clientRect', () => {
127127
const wrapper = mount(<Tab/>);
128-
wrapper.instance().tabIndicatorElement_.current.computeContentClientRect = td.func();
128+
wrapper.instance().tabIndicator_.current.computeContentClientRect = td.func();
129129
wrapper.instance().computeIndicatorClientRect();
130-
td.verify(wrapper.instance().tabIndicatorElement_.current.computeContentClientRect(), {times: 1});
130+
td.verify(wrapper.instance().tabIndicator_.current.computeContentClientRect(), {times: 1});
131131
});
132132

133133
test('#computeDimensions calls foundation.computeDimensions', () => {
@@ -244,7 +244,7 @@ test('custom tabIndicator should render with a ref attached', () => {
244244
indicatorContent={<i className='icon'>icon</i>}
245245
/>);
246246

247-
assert.instanceOf(wrapper.instance().tabIndicatorElement_.current, TabIndicator);
247+
assert.instanceOf(wrapper.instance().tabIndicator_.current, TabIndicator);
248248
});
249249

250250
test('isMinWidthIndicator renders indicator within the content element', () => {

0 commit comments

Comments
 (0)