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

Programatically control active tab for tabbar #970

Closed
r1cs1 opened this issue Aug 28, 2018 · 26 comments
Closed

Programatically control active tab for tabbar #970

r1cs1 opened this issue Aug 28, 2018 · 26 comments
Assignees
Labels
bug Experimental fix available An possibly working experimental fix is available

Comments

@r1cs1
Copy link

r1cs1 commented Aug 28, 2018

Hi guys,

I'm trying to programatically control active tab for tabbar, however neither activeTabIndex on TabBar, nor active prop on Tab is working.

Am I missing something or that's expected?

Thanks,
Richard

@cromefire
Copy link
Collaborator

Can you share how you try to do this? I think I know what's going wrong and if so a fix is on the way.

@cromefire cromefire self-assigned this Aug 28, 2018
@cromefire cromefire added bug needinfo Need more information labels Aug 28, 2018
@replaysMike
Copy link

replaysMike commented Aug 28, 2018

Oh man I just came here to ask that exact question as well. I'll show you what I did, it's an awful solution in my opinion but the docs here are pretty scarce in detail.

handleTabChange = (e) => {
	// todo: this feels old school, do Tabs component handle content selection?
	const targetName=e.toElement.getAttribute('tab');
	const panelsContainer = document.getElementById('panels');
	var panels = panelsContainer.getElementsByTagName('*');
	for(var i=0,len=panels.length; i<len; i++){
		panels[i].style = 'display: none;'
	const target = document.getElementById(targetName);
	target.style = 'display: block';
	};
}

render(props, state) {
	return (
		<div>
			<Tabs onClick={this.handleTabChange}>
				<Tabs.Tab tab="panel-1" active={true}><Icon>favorite</Icon>Tab 1</Tabs.Tab>
				<Tabs.Tab tab="panel-2">Tab 2</Tabs.Tab>
				<Tabs.Tab tab="panel-3">Tab 3</Tabs.Tab>
			</Tabs>
			<section id="panels">
				<p id="panel-1">Tab 1 Content</p>
				<p id="panel-2" hidden={true}>Tab 2 Content</p>
				<p id="panel-3" hidden={true}>Tab 3 Content</p>
			</section>
		</div>
	);
}

I hope someone else can chime in and indicate the proper way to do things, I've spent a few hours looking at the examples and source with no answer.

@replaysMike
Copy link

replaysMike commented Aug 28, 2018

In addition to that, for me I get this when trying to use the TabBar (since Tabs is marked as deprecated):

Module not found: Error: Can't resolve 'preact-material-components/TabBar'
¯\_(ツ)_/¯

@r1cs1
Copy link
Author

r1cs1 commented Aug 28, 2018

Here's a dummy example, because my code too complex to paste here. I hope I didn't mess it up .

Also, I'm using 1.5.1-beta1 because that's the only one that compiles with little mods with my typescript setup

handleClick = event => {
  this.setState({ active: +event.target.dataset.index });
}

render() {
  return (
    <TabBar>
      <TabBar.Tab onClick={this.handleClick } data-index="0" active={this.state.active === 0}>A</TabBar.Tab>
      <TabBar.Tab onClick={this.handleClick } data-index="1" active={this.state.active === 1}>B</TabBar.Tab>
      <TabBar.Tab onClick={this.handleClick } data-index="2" active={this.state.active === 2}>C</TabBar.Tab>
    </TabBar>
  )
}

@cromefire
Copy link
Collaborator

Yes I think it's a thing that is linked to #931

@cromefire
Copy link
Collaborator

@replaysMike I think your version is too old for TabBar

@cromefire cromefire added Fix in work Fix is being worked on and removed needinfo Need more information labels Aug 28, 2018
@cromefire
Copy link
Collaborator

@r1cs1 your example seems fine, as long as that +event.target.dataset.index line works fine. I will look into getting that fixed.

@replaysMike
Copy link

@cromefire indeed you seem to be right, I'm running 1.5.0 (default installed for npm install preact-material-components)

@cromefire
Copy link
Collaborator

Yes the docs are already representing the beta version and there is currently no good way to see the older docs

@cromefire
Copy link
Collaborator

@r1cs1 Also there is the activeTabIndex on TabBar, which is one of the many features left to be documented. Give it a number and it sets that one active (according to the docs).

@cromefire
Copy link
Collaborator

@r1cs1 Please try 1.5.1-experimental7 it should fix both activeTabIndex and active

@cromefire cromefire added Experimental fix available An possibly working experimental fix is available and removed Fix in work Fix is being worked on labels Aug 28, 2018
@cromefire
Copy link
Collaborator

I'm not sure, if active is working, it seems to have problems, I don't even know if that's supported anymore or there may be a problem with Tab in general.

@r1cs1
Copy link
Author

r1cs1 commented Aug 28, 2018

@cromefire now active seems to be working when it's set outside of TabBar. I mean if I set the state NOT via onclick event on the Tab elements. Basically what I want to achieve is to cancel tab switching based on some conditions. However it seems internal click handlers are more powerful :)

@r1cs1
Copy link
Author

r1cs1 commented Aug 28, 2018

@cromefire On the other hand, I always get the following error since 1.5.1-xxx

ERROR in [at-loader] ./node_modules/preact-material-components/Base/types.d.ts:2:11
    TS2322: Type 'T' is not assignable to type 'string'.
  Type 'string | number | symbol' is not assignable to type 'string'.
    Type 'number' is not assignable to type 'string'.

ERROR in [at-loader] ./node_modules/preact-material-components/Base/types.d.ts:4:11
    TS2322: Type 'U' is not assignable to type 'string'.
  Type 'string | number | symbol' is not assignable to type 'string'.
    Type 'number' is not assignable to type 'string'.

Replacing it by this code seems to solve it, but not sure if it causes any other issues or if it's correct liek that:


export declare type OmitAttrs<T extends {
    [attr: string]: any;
}, O extends {
    [attr: string]: any;
}> = Pick<T, keyof { [K in Exclude<keyof T, keyof O>]: T[K] }>

@cromefire
Copy link
Collaborator

cromefire commented Aug 28, 2018

Yes that's something that needs to be changed, doing that tomorrow (CEST).

@cromefire
Copy link
Collaborator

@r1cs1 I would try activeTabIndex anyway as it seems simpler for you and I don't really get, what you changed and mean with

internal click handlers

@prateekbh
Copy link
Owner

Yeah tabBar isn't really a prop friendly underneath.
Please use .MDComponent.setActive() on the ref of tabbar

@prateekbh
Copy link
Owner

Also same for Tabs

@prateekbh
Copy link
Owner

prateekbh commented Aug 29, 2018

Example: https://1040718yoq.codesandbox.io

P.s. swipe left right for active tabs

cromefire pushed a commit that referenced this issue Aug 29, 2018
Signed-off-by: Cromefire_ <tim.l@nghorst.net>
@r1cs1
Copy link
Author

r1cs1 commented Aug 29, 2018

@prateekbh Thanks, man! .MDComponent.activateTab(index) on the TabBar works like a charm

@cromefire
Copy link
Collaborator

So as it seems to work like this I'll close it.

prateekbh added a commit that referenced this issue Sep 5, 2018
* Release (#793)

* Doc changes (#742)

* fixing version number

* fixing env target

* changing docs language

* new deps (#741)

* new deps

* Sync with Prettier

* Sync with Prettier

* fixing docs pics

* fixing pics (#743)

* fixing pics

* Update package.json

* fixing pics

* Update docs (#785)

* fixing version number

* fixing env target

* changing docs language

* new deps (#741)

* new deps

* Sync with Prettier

* Sync with Prettier

* fixing docs pics

* fixing pics (#743)

* fixing pics

* Update package.json

* fixing pics

* upgrading to 34 (#744)

* upgrading to 34

* Sync with Prettier

* text field value support

* Sync with Prettier

* Sync with Prettier

* fixing tests

* Release docs (#790)

* fixing version number

* fixing env target

* changing docs language

* new deps (#741)

* new deps

* Sync with Prettier

* Sync with Prettier

* fixing docs pics

* fixing pics (#743)

* fixing pics

* Update package.json

* fixing pics

* upgrading to 34 (#744)

* upgrading to 34

* Sync with Prettier

* text field value support

* Sync with Prettier

* Sync with Prettier

* fixing tests

* close greenkeeper (#786)

* updating to mdc 35 (#787)

* updating to mdc 35

* Sync with Prettier

* fixing errors and adding typography

* test fix

* fixing new images

* Sync with Prettier

* adding routes in pre-render

* bug fix

* test fixes

* Prettierfix (#797)

- optional prettier fix
- hoek fix

* v1.4.5 - Fixed typings for Typography. (#798)

* Fix Tabs within TabBarScroller initialized multiple times (#796)

* 🔥 Remove `indicator-accent` from `Tabs` component

Remove `indicator-accent` from `Tabs` as it is no longer used (material-components/material-components-web#1965)

* Add TabBarScrollerTabs component

- `TabBarScrollerTabs` should be used within `TabBarScroller` instead of `Tabs`.

- Component name is inspired by class name used by @material/mdc-tab: '.mdc-tab-bar-scroller__scroll-frame__tabs'

- `scroller` property is no longer needed on `Tabs` and allows a simpler implementation

- `activeTabIndex` can be used on `Tabs` and `TabBarScroller` to select active tab index

* Fix prettier formatting

* Uptable tabs golden screenshot

* typo in import (#799)

* chore(package): update webpack-cli to version 3.0.0 (#800)

* Update @material/rtl to the latest version 🚀 (#801)

* fix(package): update @material/rtl to version 0.36.0

* Sync with Prettier

* Don't bundle a copy of Preact into dist (#826)

* Update index.js

* Updating deps (#827)

* Doc changes (#742)

* fixing version number

* fixing env target

* changing docs language

* new deps (#741)

* new deps

* Sync with Prettier

* Sync with Prettier

* fixing docs pics

* fixing pics (#743)

* fixing pics

* Update package.json

* fixing pics

* Update docs (#785)

* fixing version number

* fixing env target

* changing docs language

* new deps (#741)

* new deps

* Sync with Prettier

* Sync with Prettier

* fixing docs pics

* fixing pics (#743)

* fixing pics

* Update package.json

* fixing pics

* upgrading to 34 (#744)

* upgrading to 34

* Sync with Prettier

* text field value support

* Sync with Prettier

* Sync with Prettier

* fixing tests

* updating mdcweb

* Update package.json

* Update to v36 (#828)

* Doc changes (#742)

* fixing version number

* fixing env target

* changing docs language

* new deps (#741)

* new deps

* Sync with Prettier

* Sync with Prettier

* fixing docs pics

* fixing pics (#743)

* fixing pics

* Update package.json

* fixing pics

* Update docs (#785)

* fixing version number

* fixing env target

* changing docs language

* new deps (#741)

* new deps

* Sync with Prettier

* Sync with Prettier

* fixing docs pics

* fixing pics (#743)

* fixing pics

* Update package.json

* fixing pics

* upgrading to 34 (#744)

* upgrading to 34

* Sync with Prettier

* text field value support

* Sync with Prettier

* Sync with Prettier

* fixing tests

* adding IconButton

* Sync with Prettier

* adding icon button

* fixing screen shots

* adding docs

* Sync with Prettier

* fixing docs

* chore(package): update eslint to version 5.0.0 (#833)

* Default id for TextFieldInput (#830)

* Default id for TextFieldInput

If showDiv is false, id is not available for TextFieldInput when id not defined in props. Generate id for both.

* Update TextField.jsx

* TextField improvements (#853)

* Fixed missing dependency for prettier (+eslint rules)

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Added outlined to TextField

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Added outerStyle to TextField

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed prettier formatting

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Switched from classProperties syntax

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Added Outlined documentation and fixed documentation link for TextField

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Added outlined sample

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Added changed images for documentation tests

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Bumped version to 1.4.7

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* updating deps (#855)

* outlined select (#857)

* outlined select

* fixing ts defination

* fixing tests

* bump package.json

* Fixed visible line ripple when outlined and outerStyle in case of no helper text is shown (#856)

* Fixed visible line ripple when outlined

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed outerStyle in case no helper text is used

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Added outerStyle documentation

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Added outerStyle documentation

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed missing prop

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed label name in sample

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Updated test image to new text field documentation

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed outline="true" showing in <input> element

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Added helperTextOuterStyle to make styling of the wrapper around helper text and input possible

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Switched to intermediateStyle with defaults

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Made intermediateStyle optional

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Added updated textfield verification image

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Removed intermediateStyle

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Added image for changed documentation

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Removed unneeded default props

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Applied changes defined in review

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Also bumped version to 1.5.0

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Updated textfield doc test image

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* fixes double body (#875)

* fixes double body

* Sync with Prettier

* re-add diffs

* re-add diffs

* fixing pics

* revert threashold

* change wait to timeout

* timeout as networkidle0

* fixing screen shots

* Card: change prop 16-9 to sixteenByNine (#868)

* Card: change prop 16-9 to sixteenByNine

* add className if sixteenByNine prop is present

* updating deps (#879)

* Update index.d.ts (#861)

* fixing double render

* fixing golden docs

* Fixed imports in TopAppBar demo (#916)

* Fixed imports in TopAppBar demo

* updated the reference image

* Improve build system (#878)

* Added yarn.lock to .gitignore

to open a PR changes are required

* Added basic typescript infrastructure and moved switch to typescript

* Sync with Prettier

* Readded webpack build

* Set target to es2015 and removed webpack again

* Migrated MaterialComponent and set up tslint

* Let typescript transpile jsx syntax

* Added updated .ignores

* Added typescript parser for prettier

* Reverted parser change

* Excluding future build artifacts

* Added babel for transpiling

* Added babel options

* Fixed travis doc test to fail, if no failed images are generated

* Improved failing if compile failed

* Updated babel version

* Fixed compile fail detection

* Migrated Typography

* Migrated TopAppBar

* Migrated Toolbar

* Sync with Prettier

* Migrated TextField

* Migrated Tabs and added linting to test

* Migrated Snackbar and Slider

* Migrated Select

* Migrated Radio

* Migrated Menu and List

* Sync with Prettier

* Migrated LineRipple

* Migrated LinearProgress and LayoutGrid

* Migrated ImageList

* Migrated IconButton, IconToggle and Icon and added types for mwc

* Migrated GridList, FormField, Fab and Elevation

* Sync with Prettier

* Migrated Drawer, Dialog, Chips, Checkbox, Card and Button

* Fixed wrong references

* Fixed lint issues and readded webpack to build

* Fixed type issue with html elements

* Added autogeneration of /Component/index.d.ts and started using autobind for Component classes

* Excluded declarations from git and prettier

* Removed accidental autobind-decorator from docs

* Implemented autobind

* Fixed tslint style

* Added tslint fixer

* Fixed test script

* Sync with Prettier

* Remove still tracked js file

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed missing props and children

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Set typescript to strict mode

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed Select Page

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Sync with Prettier

* Fixed sample

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed sample

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Cleared TODOs

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed componentWillUnmount() for IconButton

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Integrated primary and secondary into MaterialComponent

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Sync with Prettier

* Revert "Integrated primary and secondary into MaterialComponent"

This reverts commit a5498b9

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Migrated primary and secondary back to Button and Fab

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed props in materialDom()

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed LinearProgress themeProp declaration

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Added disables to IconButtons mdcProps

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed /index in import

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed /index in import in .js files

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed IconButton props

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed type for onChange

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed props and added TODOs for mismatching ones

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* removing sample

* fixing a few props

* bumping version

* dont compile sample

* fixing select

* fixing tests

* Fixed types.d.ts not in generated output and switched from this.base to this.control in Select and Switch
Fixes #918

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Fixed TextFieldProps becase TextField is not a MDComponent

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Letting babel only run once

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Added babel runtime

Signed-off-by: Cromefire_ <cromefirehd@gmail.com>

* Updated .ignore Files

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Excluded .babelrc, .prettierignore and .eslintignore from npm package

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Update to38 (#919)

* updating deps

* added deprecation notice

* Fix code typo on homepage (#917)

The wrong package is being imported.

* Make the two card demos look different (#870)

* Added valid to TextFieldProps (#920)

* Added valid to TextFieldProps

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Sync with Prettier

* Changes for38 (#923)

* fixing list and switch

* implementing tab-bar

* bug fix

* Sync with Prettier

* re-order

* Fixed style

* resolving comments

* adding css file

* Sync with Prettier

* fixing golden tests

* fixing golden test

* Adjusting docs for 1.5.1 (#924)

* Added changelog for 1.5.1

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Sync with Prettier

* Updated README for 1.5.1

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Added new build system to doc page and implemented Fire Code for code

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Fixed Tab bar page code

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Fixed TabBar page typo

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Set font display to swap

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Removed component list from README

* Updated test images

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* chore(package): update eslint-config-prettier to version 3.0.0 (#925)

* Delegated MDComponent notification to MaterialComponent

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Added value to TextField notify props

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Fixed value notify prop on TextField

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Added fixed value prop to TextField

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Removed unneeded setValid

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Added disabled notification to Checkbox

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Added babel runtime as runtime dependecy (#922)

* Added babel runtime as runtime dependecy

* Sync with Prettier

* Also update classText on update

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Reverted to reversed

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Only conditionally rebuilding className

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Published 1.5.1-experimental2 from the right branch and removed docs and .idea from npm package

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Removed debug log

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Removed MDComponent hasOwnProperty check

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Fixed disabled prop accidentally removed from element

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* experimental4

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Fixed className generation on update

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Fixed className generation for TextField

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Sync with Prettier

* renamed reverse prop in docs back to reversed

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Fixed some last minor issues

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Making requested changes

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Removed value notification

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Added active notification for Tab

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Released experimental 7

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Improved TypeScript typing for soft merge (See #970)

Signed-off-by: Cromefire_ <tim.l@nghorst.net>

* Updated version to 1.5.1

Signed-off-by: Cromefire_ <tim.l@nghorst.net>
@thadeu
Copy link

thadeu commented Nov 8, 2018

Example: https://1040718yoq.codesandbox.io

P.s. swipe left right for active tabs

what is this repository?

@prateekbh
Copy link
Owner

nuka carousel

@thadeu
Copy link

thadeu commented Nov 8, 2018

@prateekbh I'd like see the code TabBar full component

@cromefire
Copy link
Collaborator

https://codesandbox.io/s/1040718yoq
That looks like something that would be nice to include in the 2.0 Tabs (in like a subclass)

@thadeu
Copy link

thadeu commented Nov 9, 2018

@cromefire thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Experimental fix available An possibly working experimental fix is available
Projects
None yet
Development

No branches or pull requests

5 participants