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(Sticky): resolved width problem #2047

Merged
merged 2 commits into from
May 30, 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
2 changes: 1 addition & 1 deletion src/sticky/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ isComponent: true
-- | -- | -- | -- | --
container | Function | - | 函数返回容器对应的 NodesRef 节点,将对应节点指定为组件的外部容器,滚动时组件会始终保持在容器范围内,当组件即将超出容器底部时,会返回原位置。 | N
disabled | Boolean | false | 是否禁用组件 | N
external-classes | Array | - | 根结点外部样式。`['t-class']` | N
external-classes | Array | - | 根结点外部样式。`['t-class', 't-class-content']` | N
offset-top | String / Number | 0 | 吸顶时与顶部的距离,单位`px` | N
z-index | Number | 99 | 吸顶时的 z-index | N

Expand Down
4 changes: 2 additions & 2 deletions src/sticky/__test__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Sticky Props', () => {

simulate.scroll($demo, 500, 4);
await simulate.sleep(20);
expect($sticky.instance.data.contentStyle).toBe('position:fixed;top:0px;');
expect($sticky.instance.data.contentStyle).toBe('position:fixed;top:0px;left:0;right:0;');
});

it(':offset-top', async () => {
Expand All @@ -46,7 +46,7 @@ describe('Sticky Props', () => {

simulate.scroll($demo, 500, 4);
await simulate.sleep(20);
expect($sticky.instance.data.contentStyle).toBe('position:fixed;top:100px;');
expect($sticky.instance.data.contentStyle).toBe('position:fixed;top:100px;left:0;right:0;');
});

it(':disabled', async () => {
Expand Down
4 changes: 0 additions & 4 deletions src/sticky/sticky.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@

.@{prefix}-sticky {
position: relative;

&__content {
width: fit-content;
}
}
4 changes: 2 additions & 2 deletions src/sticky/sticky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface StickyProps extends TdStickyProps {}

@wxComponent()
export default class Sticky extends SuperComponent {
externalClasses = [`${prefix}-class`];
externalClasses = [`${prefix}-class`, `${prefix}-class-content`];

properties = props;

Expand Down Expand Up @@ -99,7 +99,7 @@ export default class Sticky extends SuperComponent {

if (isFixed) {
containerStyle += `height:${height}px;`;
contentStyle += `position:fixed;top:${offsetTop}px;`;
contentStyle += `position:fixed;top:${offsetTop}px;left:0;right:0;`;
}
if (transform) {
const translate = `translate3d(0, ${transform}px, 0)`;
Expand Down
4 changes: 2 additions & 2 deletions src/sticky/sticky.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<view
class="{{classPrefix}} class {{prefix}}-class"
style="{{_._style(['z-index:' + zIndex, containerStyle, style, customStyle])}}"
style="{{_._style(['z-index:' + zIndex, containerStyle, style, customStyle])}};"
>
<view class="{{classPrefix}}__content" style="z-index:{{ zIndex }};{{ contentStyle }}">
<view class="{{classPrefix}}__content {{prefix}}-class-content" style="z-index:{{ zIndex }};{{ contentStyle }};">
<slot />
</view>
</view>