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

fix: tab-bar active prop #1112

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/site/web/docs/migration-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@

### Checkbox / Radio

- 组合使用时 `type` 类型可选值 `cell` 调整为 `list`。
- 废弃样式相关属性 `size`、`shape`、`ghost`,可以通过 css 变量方式更改样式。
- 组合使用时 `type` 类型可选值 `cell` 调整为 `list`。
- 废弃样式相关属性 `size`、`shape`、`ghost`,可以通过 css 变量方式更改样式。

```diff
<Checkbox.Group
Expand Down Expand Up @@ -236,6 +236,16 @@

- 移除 `format` 属性

### Tabbar

移除 `visible` 属性

```diff
<Tabbar
- visible={false}
/>
```

## 常见问题

### 如何在已经使用 Zarm 2.x 的项目中 Zarm 3.0
Expand Down
3 changes: 0 additions & 3 deletions packages/zarm/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,6 @@ describe('index', () => {
"$$typeof": Symbol(react.forward_ref),
"render": [Function],
},
"defaultProps": Object {
"visible": true,
},
"render": [Function],
},
"Tabs": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ exports[`DatePickerView meridiem hour snapshot 1`] = `
8时
</div>
<div
class="za-wheel__item"
class="za-wheel__item za-wheel__item--selected"
style="transform: rotateX(NaNdeg); transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1); transition-duration: 800ms; pointer-events: none;"
>
9时
Expand Down Expand Up @@ -376,7 +376,7 @@ exports[`DatePickerView meridiem hour snapshot 1`] = `
42分
</div>
<div
class="za-wheel__item"
class="za-wheel__item za-wheel__item--selected"
style="transform: rotateX(NaNdeg); transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1); transition-duration: 800ms; pointer-events: none;"
>
43分
Expand Down Expand Up @@ -671,7 +671,7 @@ exports[`DatePickerView snapshot 1`] = `
5月
</div>
<div
class="za-wheel__item"
class="za-wheel__item za-wheel__item--selected"
style="transform: rotateX(NaNdeg); transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1); transition-duration: 800ms; pointer-events: none;"
>
6月
Expand Down Expand Up @@ -746,7 +746,7 @@ exports[`DatePickerView snapshot 1`] = `
4日
</div>
<div
class="za-wheel__item"
class="za-wheel__item za-wheel__item--selected"
style="transform: rotateX(NaNdeg); transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1); transition-duration: 800ms; pointer-events: none;"
>
5日
Expand Down Expand Up @@ -901,12 +901,6 @@ exports[`DatePickerView snapshot 1`] = `
>
30日
</div>
<div
class="za-wheel__item"
style="transform: rotateX(NaNdeg); transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1); transition-duration: 800ms; pointer-events: none;"
>
31日
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -1203,7 +1197,7 @@ exports[`DatePickerView week snapshot 1`] = `
22周
</div>
<div
class="za-wheel__item"
class="za-wheel__item za-wheel__item--selected"
style="transform: rotateX(NaNdeg); transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1); transition-duration: 800ms; pointer-events: none;"
>
23周
Expand Down
18 changes: 2 additions & 16 deletions packages/zarm/src/tab-bar/TabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const TabBar = React.forwardRef<HTMLDivElement, TabBarProps>((props, ref) => {

const bem = createBEM('tab-bar', { prefixCls });

const { visible, className, children, onChange, activeKey, defaultActiveKey, safeArea, ...rest } =
props;
const { className, children, onChange, activeKey, defaultActiveKey, safeArea, ...rest } = props;

const [selectedKey, setSelectedKey] = useState(defaultActiveKey);

Expand Down Expand Up @@ -78,16 +77,7 @@ const TabBar = React.forwardRef<HTMLDivElement, TabBarProps>((props, ref) => {
},
);
return (
<div
{...rest}
ref={ref}
className={bem([
{
hidden: !visible,
},
className,
])}
>
<div {...rest} ref={ref} className={bem([className])}>
<div className={bem('wrapper')}>{items}</div>
{safeArea && <SafeArea position="bottom" />}
</div>
Expand All @@ -96,8 +86,4 @@ const TabBar = React.forwardRef<HTMLDivElement, TabBarProps>((props, ref) => {

TabBar.displayName = 'TabBar';

TabBar.defaultProps = {
visible: true,
};

export default TabBar;
50 changes: 1 addition & 49 deletions packages/zarm/src/tab-bar/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('TabBar', () => {

it('should select first tab bar item if activeKey and defaultActivceKey are not existed', () => {
const { container } = render(
<TabBar visible={false} className="test">
<TabBar className="test">
<TabBarItem itemKey="home" title="主页" />
<TabBarItem itemKey="about us" title="关于我们" />
</TabBar>,
Expand Down Expand Up @@ -166,52 +166,4 @@ describe('TabBar', () => {
const el = container.querySelectorAll('.za-tab-bar__item');
expect(el[0].className).toEqual('za-tab-bar__item za-tab-bar__item--active');
});

// it('should use element index as the fallback itemKey', () => {
// const wrapper = shallow(
// <TabBar>
// <TabBarItem />
// <TabBarItem />
// </TabBar>,
// );
// expect(wrapper.childAt(0).prop('itemKey')).toBe(0);
// expect(wrapper.childAt(1).prop('itemKey')).toBe(1);
// });

it('should have hidden class name if visible prop is false', () => {
const { container } = render(
<TabBar visible={false} className="test">
<TabBarItem itemKey="home" title="主页" />
</TabBar>,
);
const el = container.querySelector('.za-tab-bar');
expect(el?.classList.contains('test')).toBeTruthy();
expect(el?.classList.contains('za-tab-bar')).toBeTruthy();
expect(el?.classList.contains('za-tab-bar--hidden')).toBeTruthy();
});

// it('should render children with extra props', () => {
// const wrapper = shallow(
// <TabBar visible={false} className="test">
// <TabBarItem itemKey="home" title="主页" />
// <TabBarItem itemKey="about us" title="关于我们" />
// </TabBar>,
// );
// expect(wrapper.childAt(0).props()).toEqual(
// expect.objectContaining({
// title: '主页',
// itemKey: 'home',
// onChange: expect.any(Function),
// selected: true,
// }),
// );
// expect(wrapper.childAt(1).props()).toEqual(
// expect.objectContaining({
// title: '关于我们',
// itemKey: 'about us',
// onChange: expect.any(Function),
// selected: false,
// }),
// );
// });
});
1 change: 0 additions & 1 deletion packages/zarm/src/tab-bar/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ ReactDOM.render(<Demo />, mountNode);

| 属性 | 类型 | 默认值 | 说明 |
| :--------------- | :-------------------------------- | :----- | :------------------------- |
| visible | boolean | true | 是否显示 |
| activeKey | number \| string | - | 当前选中项 |
| defaultActiveKey | number \| string | - | 初始选中项, 默认第一个选中 |
| safeArea | boolean | false | 是否适配安全区域 |
Expand Down
1 change: 0 additions & 1 deletion packages/zarm/src/tab-bar/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ReactNode } from 'react';
import type { BaseBadgeProps } from '../badge/interface';

export interface BaseTabBarProps {
visible?: boolean;
defaultActiveKey?: string | number;
activeKey?: string | number;
safeArea?: boolean;
Expand Down