mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-18 12:34:25 +08:00
fix(layout): scrollTo
not working with native scrollbar
This commit is contained in:
parent
c5dd884df6
commit
e32b020a95
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## Pending
|
## Pending
|
||||||
|
|
||||||
|
### Breaking Changes
|
||||||
|
|
||||||
|
- `n-layout-sider` removed `show-content` prop. Please use `show-collapsed-content` instead.
|
||||||
|
|
||||||
### Feats
|
### Feats
|
||||||
|
|
||||||
- `n-data-table` support tree data.
|
- `n-data-table` support tree data.
|
||||||
@ -25,6 +29,7 @@
|
|||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
|
||||||
|
- `n-layout` & `n-layout-sider`'s `scrollTo` not working with native scrollbar.
|
||||||
- `n-layout-sider`'s `collapse-mode` not working.
|
- `n-layout-sider`'s `collapse-mode` not working.
|
||||||
- Internal selection component's theme peers has wrong key for popover.
|
- Internal selection component's theme peers has wrong key for popover.
|
||||||
|
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## Pending
|
## Pending
|
||||||
|
|
||||||
|
### Breaking Changes
|
||||||
|
|
||||||
|
- `n-layout-sider` 移除了 `show-content`,使用 `show-collapsed-content` 代替
|
||||||
|
|
||||||
### Feats
|
### Feats
|
||||||
|
|
||||||
- `n-data-table` 支持树形数据
|
- `n-data-table` 支持树形数据
|
||||||
@ -25,6 +29,7 @@
|
|||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
|
||||||
|
- `n-layout` & `n-layout-sider` 的 `scrollTo` 在使用原生滚动条时不生效
|
||||||
- `n-layout-sider` 的 `collapse-mode` 属性不生效
|
- `n-layout-sider` 的 `collapse-mode` 属性不生效
|
||||||
- 内部 selection 组件的主题 peers 中 popover 的 key 不正确
|
- 内部 selection 组件的主题 peers 中 popover 的 key 不正确
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export { default as NLayout } from './src/Layout'
|
export { default as NLayout } from './src/Layout'
|
||||||
export { default as NLayoutContent } from './src/Layout'
|
export { default as NLayoutContent } from './src/LayoutContent'
|
||||||
export { default as NLayoutHeader } from './src/LayoutHeader'
|
export { default as NLayoutHeader } from './src/LayoutHeader'
|
||||||
export { default as NLayoutFooter } from './src/LayoutFooter'
|
export { default as NLayoutFooter } from './src/LayoutFooter'
|
||||||
export { default as NLayoutSider } from './src/LayoutSider'
|
export { default as NLayoutSider } from './src/LayoutSider'
|
||||||
|
@ -40,15 +40,16 @@ export const layoutInjectionKey: InjectionKey<
|
|||||||
ExtractPropTypes<LayoutProps>
|
ExtractPropTypes<LayoutProps>
|
||||||
> = Symbol('layout')
|
> = Symbol('layout')
|
||||||
|
|
||||||
export default defineComponent({
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||||
name: 'Layout',
|
export function createLayoutComponent (isContent: boolean) {
|
||||||
alias: ['LayoutContent'],
|
return defineComponent({
|
||||||
|
name: isContent ? 'LayoutContent' : 'Layout',
|
||||||
props: {
|
props: {
|
||||||
...(useTheme.props as ThemeProps<LayoutTheme>),
|
...(useTheme.props as ThemeProps<LayoutTheme>),
|
||||||
...layoutProps
|
...layoutProps
|
||||||
},
|
},
|
||||||
setup (props) {
|
setup (props) {
|
||||||
const selfRef = ref<HTMLElement | null>(null)
|
const scrollableDivRef = ref<HTMLElement | null>(null)
|
||||||
const scrollbarRef = ref<ScrollbarInst | null>(null)
|
const scrollbarRef = ref<ScrollbarInst | null>(null)
|
||||||
const { mergedClsPrefixRef } = useConfig(props)
|
const { mergedClsPrefixRef } = useConfig(props)
|
||||||
const themeRef = useTheme(
|
const themeRef = useTheme(
|
||||||
@ -65,8 +66,8 @@ export default defineComponent({
|
|||||||
): void => {
|
): void => {
|
||||||
if (scrollbarRef.value) {
|
if (scrollbarRef.value) {
|
||||||
scrollbarRef.value.scrollTo(options as any, y as any)
|
scrollbarRef.value.scrollTo(options as any, y as any)
|
||||||
} else if (selfRef.value) {
|
} else if (scrollableDivRef.value) {
|
||||||
selfRef.value.scrollTo(options as any, y as any)
|
scrollableDivRef.value.scrollTo(options as any, y as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const scrollableDivStyleRef = computed(() => {
|
const scrollableDivStyleRef = computed(() => {
|
||||||
@ -81,7 +82,7 @@ export default defineComponent({
|
|||||||
if (__DEV__) provide(layoutInjectionKey, props)
|
if (__DEV__) provide(layoutInjectionKey, props)
|
||||||
return {
|
return {
|
||||||
mergedClsPrefix: mergedClsPrefixRef,
|
mergedClsPrefix: mergedClsPrefixRef,
|
||||||
selfRef,
|
scrollableDivRef,
|
||||||
scrollbarRef,
|
scrollbarRef,
|
||||||
scrollableDivStyle: scrollableDivStyleRef,
|
scrollableDivStyle: scrollableDivStyleRef,
|
||||||
scrollTo,
|
scrollTo,
|
||||||
@ -103,8 +104,8 @@ export default defineComponent({
|
|||||||
const { mergedClsPrefix } = this
|
const { mergedClsPrefix } = this
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref="selfRef"
|
|
||||||
class={[
|
class={[
|
||||||
|
isContent && `${mergedClsPrefix}-layout-content`,
|
||||||
`${mergedClsPrefix}-layout`,
|
`${mergedClsPrefix}-layout`,
|
||||||
`${mergedClsPrefix}-layout--${this.position}-positioned`,
|
`${mergedClsPrefix}-layout--${this.position}-positioned`,
|
||||||
this.hasSider && `${mergedClsPrefix}-layout--has-sider`
|
this.hasSider && `${mergedClsPrefix}-layout--has-sider`
|
||||||
@ -124,6 +125,7 @@ export default defineComponent({
|
|||||||
</NScrollbar>
|
</NScrollbar>
|
||||||
) : (
|
) : (
|
||||||
<div
|
<div
|
||||||
|
ref="scrollableDivRef"
|
||||||
class={`${mergedClsPrefix}-layout__content`}
|
class={`${mergedClsPrefix}-layout__content`}
|
||||||
style={this.scrollableDivStyle}
|
style={this.scrollableDivStyle}
|
||||||
>
|
>
|
||||||
@ -133,4 +135,7 @@ export default defineComponent({
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default createLayoutComponent(false)
|
||||||
|
3
src/layout/src/LayoutContent.tsx
Normal file
3
src/layout/src/LayoutContent.tsx
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { createLayoutComponent } from './Layout'
|
||||||
|
|
||||||
|
export default createLayoutComponent(true)
|
@ -48,7 +48,7 @@ const layoutSiderProps = {
|
|||||||
default: undefined
|
default: undefined
|
||||||
},
|
},
|
||||||
defaultCollapsed: Boolean,
|
defaultCollapsed: Boolean,
|
||||||
showContent: {
|
showCollapsedContent: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
},
|
},
|
||||||
@ -106,7 +106,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const selfRef = ref<HTMLElement | null>(null)
|
const scrollableDivRef = ref<HTMLElement | null>(null)
|
||||||
const scrollbarRef = ref<ScrollbarInst | null>(null)
|
const scrollbarRef = ref<ScrollbarInst | null>(null)
|
||||||
const styleMaxWidthRef = computed(() => {
|
const styleMaxWidthRef = computed(() => {
|
||||||
return formatLength(
|
return formatLength(
|
||||||
@ -140,11 +140,11 @@ export default defineComponent({
|
|||||||
function scrollTo (options: ScrollToOptions | number, y?: number): void {
|
function scrollTo (options: ScrollToOptions | number, y?: number): void {
|
||||||
if (scrollbarRef.value) {
|
if (scrollbarRef.value) {
|
||||||
scrollbarRef.value.scrollTo(options as any, y as any)
|
scrollbarRef.value.scrollTo(options as any, y as any)
|
||||||
} else if (selfRef.value) {
|
} else if (scrollableDivRef.value) {
|
||||||
if (y === undefined) {
|
if (y === undefined) {
|
||||||
selfRef.value.scrollTo(options as any)
|
scrollableDivRef.value.scrollTo(options as any)
|
||||||
} else {
|
} else {
|
||||||
selfRef.value.scrollTo(options as any, y as any)
|
scrollableDivRef.value.scrollTo(options as any, y as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ export default defineComponent({
|
|||||||
mergedClsPrefixRef
|
mergedClsPrefixRef
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
selfRef,
|
scrollableDivRef,
|
||||||
scrollbarRef,
|
scrollbarRef,
|
||||||
mergedClsPrefix: mergedClsPrefixRef,
|
mergedClsPrefix: mergedClsPrefixRef,
|
||||||
mergedTheme: themeRef,
|
mergedTheme: themeRef,
|
||||||
@ -227,13 +227,13 @@ export default defineComponent({
|
|||||||
const { mergedClsPrefix } = this
|
const { mergedClsPrefix } = this
|
||||||
return (
|
return (
|
||||||
<aside
|
<aside
|
||||||
ref="selfRef"
|
|
||||||
class={[
|
class={[
|
||||||
`${mergedClsPrefix}-layout-sider`,
|
`${mergedClsPrefix}-layout-sider`,
|
||||||
`${mergedClsPrefix}-layout-sider--${this.position}-positioned`,
|
`${mergedClsPrefix}-layout-sider--${this.position}-positioned`,
|
||||||
this.bordered && `${mergedClsPrefix}-layout-sider--bordered`,
|
this.bordered && `${mergedClsPrefix}-layout-sider--bordered`,
|
||||||
this.mergedCollapsed && `${mergedClsPrefix}-layout-sider--collapsed`,
|
this.mergedCollapsed && `${mergedClsPrefix}-layout-sider--collapsed`,
|
||||||
this.showContent && `${mergedClsPrefix}-layout-sider--show-content`
|
(!this.mergedCollapsed || this.showCollapsedContent) &&
|
||||||
|
`${mergedClsPrefix}-layout-sider--show-content`
|
||||||
]}
|
]}
|
||||||
style={[
|
style={[
|
||||||
this.cssVars,
|
this.cssVars,
|
||||||
@ -269,6 +269,7 @@ export default defineComponent({
|
|||||||
<div
|
<div
|
||||||
class={`${mergedClsPrefix}-layout-sider__content`}
|
class={`${mergedClsPrefix}-layout-sider__content`}
|
||||||
style={this.scrollableDivStyle}
|
style={this.scrollableDivStyle}
|
||||||
|
ref="scrollableDivRef"
|
||||||
>
|
>
|
||||||
{this.$slots}
|
{this.$slots}
|
||||||
</div>
|
</div>
|
||||||
|
@ -26,6 +26,7 @@ export default cB('layout', `
|
|||||||
`)
|
`)
|
||||||
])
|
])
|
||||||
]),
|
]),
|
||||||
|
cE('content', 'box-sizing: border-box;'),
|
||||||
cM('absolute-positioned', `
|
cM('absolute-positioned', `
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user