Giter VIP home page Giter VIP logo

tabs's Introduction

rc-tabs


React Tabs component.

NPM version dumi build status Test coverage npm download bundle size

Screenshot

Example

http://localhost:8000/examples

online example: https://tabs.react-component.now.sh/

install

rc-tabs

Feature

Keyboard

  • left and up: tabs to previous tab
  • right and down: tabs to next tab

Usage

import Tabs from 'rc-tabs';
import ReactDom from 'react-dom';

const callback = (key) => {
  console.log(key);
};

const items = [
  {
    key: '1',
    label: 'Google',
    children: (
      <div className="text-xl">
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting</p>
      </div>
    ),
  },
  {
    key: '2',
    label: <p>Amazon</p>,
    children:
      'Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...',
    disabled: true,
  },
  {
    key: '3',
    label: <p>Twitter</p>,
    children: (
      <div>
        "There is no one who loves pain itself, who seeks after it and wants to have it, simply
        because it is pain..."
      </div>
    ),
  },
];

ReactDom.render(
  <Tabs
    tabPosition="bottom"
    items={items}
    defaultActiveKey="1"
    className="md:w-[70%] w-full mx-auto p-2 border-0"
    onChange={callback}
    style={{ color: 'yellow' }}
  />,
  root,
);

API

Tabs

name type default description
prefixCls string 'rc-tabs' prefix class name, use to custom style
className string - to define a class name for an element
style CSS properties - object with css properties for styling
items TabItem[] [] configure tab content
id string - unique identifier
defaultActiveKey string - initial active tabPanel's key if activeKey is absent
activeKey string - current active tabPanel's key
direction 'ltr' or 'rtl' 'ltr' Layout direction of tabs component
animated boolean | { inkBar: boolean, tabPane: boolean } { inkBar: true, tabPane: false } config animation
renderTabBar (props, TabBarComponent) => ReactElement - How to render tab bar
tabBarExtraContent ReactNode | { left: ReactNode, right: ReactNode } - config extra content
tabBarGutter number 0 config tab bar gutter
tabBarPosition 'left' | 'right' | 'top' | 'bottom' 'top' tab nav 's position
tabBarStyle style - tab nav style
tabPosition 'left' or 'right' or 'top' or 'bottom' 'top' tab nav 's position
destroyInactiveTabPane boolean false whether destroy inactive TabPane when change tab
onChange (key) => void - called when tabPanel is changed
onTabClick (key) => void - called when tab click
onTabScroll ({ direction }) => void - called when tab scroll
editable { onEdit(type: 'add' 'remove', info: { key, event }), showAdd: boolean, removeIcon: ReactNode, addIcon: ReactNode } -
locale { dropdownAriaLabel: string, removeAriaLabel: string, addAriaLabel: string } - Accessibility locale help text
moreIcon ReactNode - collapse icon

TabItem

name type default description
key string - corresponding to activeKey, should be unique
label string - TabPane's head display text
tab ReactNode - current tab's title corresponding to current tabPane
className string - to define a class name for an element
style CSS properties - object with css properties for styling
disabled boolean false set TabPane disabled
children ReactNode - TabPane's head display content
forceRender boolean false forced render of content in tabs, not lazy render after clicking on tabs
closable boolean false closable feature of tab item
closeIcon ReactNode - Config close icon
prefixCls string 'rc-tabs-tab' prefix class name, use to custom style
id string - unique identifier
animated boolean | { inkBar: boolean, tabPane: boolean } { inkBar: true, tabPane: false } config animation
destroyInactiveTabPane boolean false whether destroy inactive TabPane when change tab
active boolean false active feature of tab item
tabKey string - key linked to tab

TabPane(support in older versions)

name type default description
destroyInactiveTabPane boolean false whether destroy inactive TabPane when change tab
key string - corresponding to activeKey, should be unique
forceRender boolean false forced render of content in tabs, not lazy render after clicking on tabs
tab ReactNode - current tab's title corresponding to current tabPane
closeIcon ReactNode - Config close icon

Development

npm install
npm start

Test Case

npm test
npm run chrome-test

Coverage

npm run coverage

open coverage/ dir

License

rc-tabs is released under the MIT license.

FAQ

Responsive Tabs

There are 3 cases when handling responsive tabs: image

We get hidden tabs through useVisibleRange.ts. If enconter the third case, in order to make tabs responsive, some tabs should be hidden. So we minus addSize when calculating basicSize manully, even though there's no addNode in container. In this way, case 3 turns to case 2, tabs become stable again.

tabs's People

Contributors

abramo-bagnara avatar afc163 avatar alexkb0009 avatar benjycui avatar chilijung avatar dependabot-preview[bot] avatar dependabot[bot] avatar gyh9457 avatar heskeybaozi avatar jljsj33 avatar kerm1it avatar kiner-tang avatar li-jia-nan avatar madccc avatar orzyyyy avatar paranoidjk avatar picodoth avatar rinick avatar saeedrahimi avatar silentcloud avatar trickypi avatar ttys026 avatar valleykid avatar varundhand avatar wmertens avatar yesmeck avatar yiminghe avatar yoyo837 avatar yuantongkang avatar zombiej avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tabs's Issues

Cannot read property 'getBoundingClientRect' of undefined

I am getting following error:
Tabs.js:118 Uncaught TypeError: Cannot read property 'getBoundingClientRect' of undefined(…)(anonymous function) @ Tabs.js:118
Tabs.js:118 Uncaught TypeError: Cannot read property 'getBoundingClientRect' of undefined(…)(anonymous function) @ Tabs.js:118

CSS file is not included to the component by default

For some reason /assets/index.css is not included by component rc-tabs its own and thats why I need to include it separately in any my component where I want to use rc-tabs`.

Example of thing I need to do
import Tabs, {TabPane} from 'rc-tabs'; import 'rc-tabs/assets/index.css'; // TODO: Get why it is not imported with 'rc-tabs' component

I am not sure it`s a bug, but it looks like not a nice planned feature.

Why is it so?

请问代码是用哪种方式打包构建的?

您好,我分别用git和npm下载了tabs控件的代码,原以为git下载的应该是源码,然后用某种工具,如grunt或者glup来打包构建出前端可以引用的代码也就是npm install 出来的东西,可是当我打开两边的代码时,让我很困惑,到底是用哪种方式构建打包的,前端最后才能引用到,可能是我前端知识有限,所以请教一下您是用哪种方式打包构建的,git下载的代码和npm install的代码之间的关系是什么,npm install 完的代码我还要用哪种方式来引用,这样我前端才能用呢,谢谢。

getOffsetWH retrieve the wrong size

In getOffsetWH instead to use offsetWidth/offsetHeight we should use scrollWidth/scrollHeight otherwise we get the wrong size for div.ant-tabs-nav leading to wrong scroll offset computation.

Tell me if you prefer a PR.

Type of top component "Tabs" exception in v5.9.1

Hi yiminghe:

When I update rc-tabs from v5.7.0 to 5.9.1, I got React.createElement typ error: he first param of React.createElement should be a string or React Class( function ). So I console the top component Tabs like below:

let Tabs = require( 'rc-tabs' );
console.log( Tabs )

I got an Object , I suppose Tabs should be a React Class. I am not sure whether it is an issue. I refer to react official doc, and not find that React.createElement can accept an object as the first param.

ps:
I update my react to v15.0.2. I still got this exception. Below is error info in console:

rctabletest.js:1014 Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of App.

rctabletest.js:633 Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of App.

rc-tabs 移动端优化

新属性:

  • allowScroll defaults to true
  • allowInkBar defaults to true

设为 false 可简化 dom 结构

support props.scrollToActive

<Tabs scrollToActive={true|false} />

The nav always scroll to show current active tab.

When you create a new tab In scroll tabs, this new tab is active and it should be visible in view-box.

Wrong layout in new version

screen shot 2016-08-23 at 10 07 52 pm

  1. extraContent 和 tab 没有在一行
  2. tab 宽度也不对了
  3. 一些重叠了,一些掉下去了……惨不忍睹

Update API Documentation

I am using this module and I needed to force the child Render at the start up.

Firstly, I read your documentation and I didn't find any solution. However, I also checked your code and I found a TabPane props that solved my problem.

forceRender: PropTypes.bool

It would be important to update the API documentation.

tab切换时, 内容的高度显示不正确

有tabA和TabB两个tab, 对应的content是contentA和contentB, contentA的高是50px, contentB的高是100px, 当通过拖动内容区域的方式从contentA切换到contentB的过程中, contentB的高度显示不正确

Tabs.activeKeyIsValid must check if 'key' exist

function activeKeyIsValid(props, key) {
  const keys = React.Children.map(props.children, child => child.key);
  return keys.indexOf(key) >= 0;
}

If the children contains a non-object child (null, false), the:

const keys = React.Children.map(props.children, child => child.key);

it's raising an error.

It should compact the children to remove non-object values.

I can create a PR for this.

关于组件被其他组件继承问题

我在 carousel 继承了 tabs 组件,但是我修改了 prefixCls 类名,那么样式就不能复用了。

有方法通过 prefixCls 修改也修改样式的类型,让父组件的样式也会继承复用吗?

Unknown prop `defaultActiveKey` on <tabs> tag

Warning: Unknown prop `defaultActiveKey` on <tabs> tag. Remove this prop from the element. For details, see https://fb.me/react-unknown-prop
    in tabs (created by Head)
    in Head (created by Home)
    in div (created by Home)
    in Home (created by RouterContext)
    in RouterContext (created by Router)
    in Router (created by Unknown)
    in Provider (created by Unknown)
    in Unknown

Using only one of the tab bars

Is it possible to only use the tab bar, and providing our own content inside them? I want to handle the click of a tab using my own code.

能否支持switchTab 接口?

如果我要点击某个按钮, 使得切换到指定的tab, 这个如何实现? 好像setActiveKey 这个接口并没有暴露出来。

option to disable key events

I think a boolean prop that enables/disables the key event listeners would make a great addition.
If you agree I'm happy to create a PR :)

Scrollable Tabs issue

Hello,

I have came across an issue related to scrollable tabs. I have UI such as Parent tabs with tabBarPosition:'left' and child tabs with tabBarPosition:'top'.

I want to make child tab as ScrollableInkTabBar so i can scroll it horizontally. The issue is due to parent tab having tabBarPosition:'left', the scroll navigation is not visible some how. If I change parent tabBarPosition to 'top' then scroll navigation is visible perfectly.

Also, one more issue is there if I set like this, the height for child tab is increased to 99999px automatically.

Hence, I strongly feel there is some issue while we set parent tab position to 'left'. Attached screenshots for reference.

Please do the needful.

Regards,
Romil
no_navigation
with_navigation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.