fix(Tabs): should not render line when have no tab (#10063)

This commit is contained in:
neverland 2021-12-18 11:56:13 +08:00 committed by GitHub
parent 56b210156e
commit f6a835721c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 27 deletions

View File

@ -121,27 +121,15 @@ exports[`should allow to set name prop 1`] = `
`; `;
exports[`should emit rendered event after tab is rendered 1`] = ` exports[`should emit rendered event after tab is rendered 1`] = `
DOMWrapper { <div id="van-tab"
"isDisabled": [Function], role="tabpanel"
"style": CSSStyleDeclaration { class="van-tab__panel"
"_importants": Object {}, tabindex="0"
"_length": 0, aria-labelledby="van-tabs-0"
"_onChange": [Function], style
"_values": Object {}, >
}, Text
"wrapperElement": <div </div>
aria-labelledby="van-tabs-0"
class="van-tab__panel"
id="van-tab"
role="tabpanel"
style=""
tabindex="0"
>
Text
</div>,
}
`; `;
exports[`should not render empty tab 1`] = ` exports[`should not render empty tab 1`] = `

View File

@ -219,8 +219,6 @@ exports[`should render nav-bottom slot correctly 1`] = `
class="van-tabs__nav van-tabs__nav--line" class="van-tabs__nav van-tabs__nav--line"
aria-orientation="horizontal" aria-orientation="horizontal"
> >
<div class="van-tabs__line">
</div>
</div> </div>
</div> </div>
Nav Bottom Nav Bottom

View File

@ -256,7 +256,7 @@ test('should emit rendered event after tab is rendered', async () => {
await later(); await later();
expect(onRendered).toHaveBeenCalledWith('a', 'title1'); expect(onRendered).toHaveBeenCalledWith('a', 'title1');
expect(wrapper.find('.van-tab__panel')).toMatchSnapshot(); expect(wrapper.find('.van-tab__panel').html()).toMatchSnapshot();
const tabs = wrapper.findAll('.van-tab'); const tabs = wrapper.findAll('.van-tab');
await tabs[1].trigger('click'); await tabs[1].trigger('click');

View File

@ -384,6 +384,12 @@ export default defineComponent({
/> />
)); ));
const renderLine = () => {
if (props.type === 'line' && children.length) {
return <div class={bem('line')} style={state.lineStyle} />;
}
};
const renderHeader = () => { const renderHeader = () => {
const { type, border } = props; const { type, border } = props;
return ( return (
@ -403,9 +409,7 @@ export default defineComponent({
> >
{slots['nav-left']?.()} {slots['nav-left']?.()}
{renderNav()} {renderNav()}
{type === 'line' && ( {renderLine()}
<div class={bem('line')} style={state.lineStyle} />
)}
{slots['nav-right']?.()} {slots['nav-right']?.()}
</div> </div>
</div> </div>