Skip to content

Commit 2073896

Browse files
authored
fix(tabbar): add props placeholder #1692 (#1796)
1 parent 66542d0 commit 2073896

File tree

6 files changed

+71
-6
lines changed

6 files changed

+71
-6
lines changed

src/packages/__VUE/actionsheet/doc.en-US.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ActionSheet, Popup, OverLay } from '@nutui/nutui-taro';
1515
const app = createApp();
1616
app.use(ActionSheet);
1717
app.use(Popup);
18+
app.use(OverLay);
1819
```
1920

2021
### Basic Usage

src/packages/__VUE/actionsheet/doc.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ActionSheet, Popup, OverLay } from '@nutui/nutui-taro';
1515
const app = createApp();
1616
app.use(ActionSheet);
1717
app.use(Popup);
18+
app.use(OverLay);
1819
```
1920

2021
### 基础用法

src/packages/__VUE/tabbar/doc.en-US.md

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ If you need to use more icons based on the existing Icon, please refer to the Ic
185185
| unactive-color | Color of unactive tab item | string | #7d7e80 |
186186
| active-color | Color of active tab item | string | #1989fa |
187187
| safe-area-inset-bottom | Whether to enable bottom safe area adaptation | boolean | false |
188+
| placeholder `3.2.6` | Whether to generate a placeholder element when fixed | boolean | false |
188189
### TabbarItem Props
189190

190191
| Attribute | Description | Type | Default |

src/packages/__VUE/tabbar/doc.md

+1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ app.use(TabbarItem);
240240
| to `小程序不支持` | 标签页的路由对象,等于 vue-router 的 [to 属性](https://router.vuejs.org/zh/api/#to) 属性 | string|object | -- |
241241
| num | 页签右上角的数字角标,超出99之后为99+ | number | -- |
242242
| dot | 是否显示图标右上角小红点 | boolean | false |
243+
| placeholder `3.2.6` | 固定在底部时,是否在标签位置生成一个等高的占位元素 | boolean | false |
243244

244245

245246
### Tabbar Events

src/packages/__VUE/tabbar/index.taro.vue

+35-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
<template>
2-
<view class="nut-tabbar" :class="{ 'nut-tabbar-bottom': bottom, 'nut-tabbar-safebottom': safeAreaInsetBottom }">
2+
<div v-if="bottom && placeholder" class="nut-tabbar__placeholder" :style="{ height: height + 'px' }">
3+
<view
4+
ref="nutTabbar"
5+
class="nut-tabbar"
6+
:class="{ 'nut-tabbar-bottom': bottom, 'nut-tabbar-safebottom': safeAreaInsetBottom }"
7+
>
8+
<slot></slot>
9+
</view>
10+
</div>
11+
<view
12+
v-else
13+
class="nut-tabbar"
14+
:class="{ 'nut-tabbar-bottom': bottom, 'nut-tabbar-safebottom': safeAreaInsetBottom }"
15+
>
316
<slot></slot>
417
</view>
518
</template>
619

720
<script lang="ts">
8-
import { provide, reactive, watch } from 'vue';
21+
import { onMounted, provide, reactive, ref, toRefs, watch } from 'vue';
922
import { createComponent } from '@/packages/utils/create';
23+
import Taro from '@tarojs/taro';
1024
const { create } = createComponent('tabbar');
1125
export default create({
1226
props: {
@@ -37,14 +51,20 @@ export default create({
3751
safeAreaInsetBottom: {
3852
type: Boolean,
3953
default: false
54+
},
55+
placeholder: {
56+
type: Boolean,
57+
default: false
4058
}
4159
},
4260
emits: ['tab-switch', 'update:visible'],
4361
setup(props, { emit, slots }) {
62+
const { bottom, placeholder } = toRefs(props);
4463
const mdValue = reactive({
4564
val: props.visible,
4665
children: []
4766
});
67+
const height = ref();
4868
function changeIndex(index: number, active: number | string) {
4969
emit('update:visible', active);
5070
parentData.modelValue = active;
@@ -65,8 +85,20 @@ export default create({
6585
parentData.modelValue = value;
6686
}
6787
);
88+
onMounted(() => {
89+
if (bottom.value && placeholder.value) {
90+
setTimeout(() => {
91+
const query = Taro.createSelectorQuery();
92+
query.select('.nut-tabbar').boundingClientRect();
93+
query.exec((res) => {
94+
height.value = res[0].height;
95+
});
96+
}, 500);
97+
}
98+
});
6899
return {
69-
changeIndex
100+
changeIndex,
101+
height
70102
};
71103
}
72104
});

src/packages/__VUE/tabbar/index.vue

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
<template>
2-
<view class="nut-tabbar" :class="{ 'nut-tabbar-bottom': bottom, 'nut-tabbar-safebottom': safeAreaInsetBottom }">
2+
<div v-if="bottom && placeholder" class="nut-tabbar__placeholder" :style="{ height: height + 'px' }">
3+
<view
4+
ref="nutTabbar"
5+
class="nut-tabbar"
6+
:class="{ 'nut-tabbar-bottom': bottom, 'nut-tabbar-safebottom': safeAreaInsetBottom }"
7+
>
8+
<slot></slot>
9+
</view>
10+
</div>
11+
<view
12+
v-else
13+
class="nut-tabbar"
14+
:class="{ 'nut-tabbar-bottom': bottom, 'nut-tabbar-safebottom': safeAreaInsetBottom }"
15+
>
316
<slot></slot>
417
</view>
518
</template>
619

720
<script lang="ts">
8-
import { provide, reactive, watch } from 'vue';
21+
import { onMounted, provide, reactive, toRefs, ref, watch, nextTick } from 'vue';
922
import { createComponent } from '@/packages/utils/create';
1023
const { create } = createComponent('tabbar');
1124
export default create({
@@ -37,14 +50,21 @@ export default create({
3750
safeAreaInsetBottom: {
3851
type: Boolean,
3952
default: false
53+
},
54+
placeholder: {
55+
type: Boolean,
56+
default: false
4057
}
4158
},
4259
emits: ['tab-switch', 'update:visible'],
4360
setup(props, { emit, slots }) {
61+
const { bottom, placeholder } = toRefs(props);
62+
const height = ref();
4463
const mdValue = reactive({
4564
val: props.visible,
4665
children: []
4766
});
67+
const nutTabbar = ref<HTMLElement | null>(null);
4868
function changeIndex(index: number, active: number | string) {
4969
emit('update:visible', active);
5070
parentData.modelValue = active;
@@ -65,9 +85,18 @@ export default create({
6585
parentData.modelValue = value;
6686
}
6787
);
88+
onMounted(() => {
89+
if (bottom.value && placeholder.value) {
90+
nextTick(() => {
91+
height.value = nutTabbar?.value?.getBoundingClientRect().height;
92+
});
93+
}
94+
});
6895
6996
return {
70-
changeIndex
97+
changeIndex,
98+
nutTabbar,
99+
height
71100
};
72101
}
73102
});

0 commit comments

Comments
 (0)