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

Tabs无法使用Sticky标签包裹选项卡头 #1287

Closed
and80506 opened this issue May 9, 2017 · 11 comments
Closed

Tabs无法使用Sticky标签包裹选项卡头 #1287

and80506 opened this issue May 9, 2017 · 11 comments
Assignees
Labels
Milestone

Comments

@and80506
Copy link

and80506 commented May 9, 2017

What problem does this feature solve?

需求场景:

   使用react-sticky实现tabs选项卡头置顶效果。由于目前的API选项卡头显示文字是配置在TabPane的属性中,导致无法使用Sticky标签包裹选项卡头。

需求用例:

   目前受限于API只能实现选显卡头和选项卡内容一起置顶的效果。
import { Tabs } from 'antd-mobile';
import { StickyContainer, Sticky } from 'react-sticky';
const TabPane = Tabs.TabPane;
<StickyContainer>
<Sticky>
    <Tabs defaultActiveKey="2">
      <TabPane tab="选项卡一" key="1">
        <div>
          选项卡一内容
        </div>
      </TabPane>
      <TabPane tab="选项卡二" key="2">
        <div>
          选项卡二内容
        </div>
      </TabPane>
      <TabPane tab="选项卡三" key="3">
        <div>
          选项卡三内容
        </div>
      </TabPane>
    </Tabs>
</Sticky>
</StickyContainer>

What does the proposed API look like?

Tabs.TabTitle

属性 说明 类型 默认值
key 对应 activeKey String
import { Tabs } from 'antd-mobile';
import { StickyContainer, Sticky } from 'react-sticky';
const TabPane = Tabs.TabPane;
const TabTitle = Tabs.TabTitle;
<StickyContainer>
<Sticky>
    <Tabs defaultActiveKey="2">
        <TabTitle key="1">选项卡一</TabTitle>
        <TabTitle key="2">选项卡二</TabTitle>
        <TabTitle key="3">选项卡三</TabTitle>
    </Tabs>
</Sticky>
<Tabs>
      <TabPane key="1">
        <div>
          选项卡一内容
        </div>
      </TabPane>
      <TabPane key="2">
        <div>
          选项卡二内容
        </div>
      </TabPane>
      <TabPane key="3">
        <div>
          选项卡三内容
        </div>
      </TabPane>
</Tabs>
</StickyContainer>
@paranoidjk
Copy link
Contributor

antd-mobile 的 Tab 都没有 Tab.TabTitle?

请写清楚你的版本,最好提供一个 codepen demo

@and80506
Copy link
Author

我想讨论的是能否支持新的API-比如新增TabTitile,无法提供可运行的codepen demo。

@paranoidjk
Copy link
Contributor

@and80506 先给出你使用有问题的demo,我们才好决定是否要新增API来解决这个问题。

ant-design/ant-design#5165 这个你可以看下

@and80506
Copy link
Author

需求场景是实现tabs选项卡头页面滑动到底部时置顶。
demo就是前面贴出来的需求用例,这个demo只能实现tabs选项卡头和内容一起置顶的效果:

import { Tabs } from 'antd-mobile';
import { StickyContainer, Sticky } from 'react-sticky';
const TabPane = Tabs.TabPane;
<StickyContainer>
<Sticky>
    <Tabs defaultActiveKey="2">
      <TabPane tab="选项卡一" key="1">
        <div>
          选项卡一内容
        </div>
      </TabPane>
      <TabPane tab="选项卡二" key="2">
        <div>
          选项卡二内容
        </div>
      </TabPane>
      <TabPane tab="选项卡三" key="3">
        <div>
          选项卡三内容
        </div>
      </TabPane>
    </Tabs>
</Sticky>
</StickyContainer>

看了这个issues:Tabs的title如何实现置顶 结合API发现没有办法实现,猜想原因是tabs的API设计,试着改API来实现这个。

import { Tabs } from 'antd-mobile';
import { StickyContainer, Sticky } from 'react-sticky';
const TabPane = Tabs.TabPane;
const TabTitle = Tabs.TabTitle;
<StickyContainer>
<Sticky>
    <Tabs defaultActiveKey="2">
        <TabTitle key="1">选项卡一</TabTitle>
        <TabTitle key="2">选项卡二</TabTitle>
        <TabTitle key="3">选项卡三</TabTitle>
    </Tabs>
</Sticky>
<Tabs>
      <TabPane key="1">
        <div>
          选项卡一内容
        </div>
      </TabPane>
      <TabPane key="2">
        <div>
          选项卡二内容
        </div>
      </TabPane>
      <TabPane key="3">
        <div>
          选项卡三内容
        </div>
      </TabPane>
</Tabs>
</StickyContainer>

@warmhug
Copy link
Contributor

warmhug commented May 10, 2017

这个除了 #346 外,也跟 #734 (comment) 这里的 TabBar 路由跳转问题 有些共性。
tabs 的设计可能需要更复杂、来更灵活适应各种情况。

比如 TabTitle 和 TabPane 没必要是一一对应关系, 应该以 TabTitle 为主,TabPane 为辅,没设置 TabPane 时、支持自动生成 pane 容器。这种容器类组件,可以类似 RN listview API 设计

<Tabs 
  dataSource={[{title: 'title', panel: 'main content'}, {title: 'title1', panel: 'main content1'}]} 
  renderTitleWrap={() => <Sticky></Sticky>} 
  renderTitle={t => <div>{t}</div>}
  renderPaneWrap={() => <div></div>}
  renderPane={p => <div>{p}</div>}
/>

@silentcloud
Copy link
Contributor

silentcloud commented May 11, 2017

赞同 @warmhug 说的这种方式,这样改造之后, segmentcontrol(无 panel)、tabbar 也可以公用底层;

另外我们的组件不一定都非得用 rc-xxx 来做底层,毕竟起初 rc 是以 pc 起始的,mobile 端要尽量做到简单,代码量少,这也是 2.0 的目标,包大小的问题

@warmhug warmhug mentioned this issue May 11, 2017
33 tasks
@and80506
Copy link
Author

@warmhug 更加灵活的API设计比如renderTitleWrap也能很好满足此类需求,非常赞!

@yesmeck yesmeck self-assigned this May 23, 2017
@is7and11
Copy link

is7and11 commented Jun 4, 2017

@and80506 请问后来有找到解决的方法吗? 我也有遇到相同的情境. 上网找了一阵子.没有找到.

@silentcloud
Copy link
Contributor

@is7and11 这个要等到 2.0,重构 api 了

@is7and11
Copy link

is7and11 commented Jun 5, 2017

@silentcloud 好的.謝謝

@paranoidjk
Copy link
Contributor

@zhang740

评估下上面 @warmhug 提议的新 api 设计。如果这个 重构/重做,可以顺便把 rc-hammerjs 用 https://github.com/react-component/gesture 替代。#1565

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants