Skip to content

Commit

Permalink
fix(comp: affix): style is not recalculated when resizing (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzaijiang committed Jan 24, 2022
1 parent 9745c32 commit 9cda3d0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/components/affix/src/Affix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,24 @@ export default defineComponent({

const throttleMeasure = throttleRAF(measure)

function measure() {
function measure(event?: unknown) {
if (!affixRef.value || !targetRef.value) {
return
}
const affixRect = getTargetRect(affixRef.value, targetRef.value)
isStickyRef.value = isSticky(affixRect, offset.value)
contentStyle.value = calcPosition(affixRect, offset.value, targetRef.value)
if (isStickyRef.value && contentRef.value) {
if (event && (event as Event).type === 'resize') {
clearStyle()

nextTick(() => {
measure()
})

return
}

const { width, height } = getTargetSize(contentRef.value)
contentStyle.value = {
...contentStyle.value,
Expand All @@ -69,6 +79,11 @@ export default defineComponent({
}
}

function clearStyle() {
affixStyle.value = {}
contentStyle.value = {}
}

onMounted(() => {
nextTick(() => {
initContainer()
Expand Down

0 comments on commit 9cda3d0

Please sign in to comment.