-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Table] fix editable-cell can not exit (#2055)
* fix(table): editable-cell can not exit * fix(hooks useresizeobserver): add comment; remove neccessary warn * fix: remove useless params e
- Loading branch information
Showing
2 changed files
with
28 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,39 @@ | ||
import { Ref, onMounted, onBeforeUnmount } from '@vue/composition-api'; | ||
import { Ref, watch, onBeforeUnmount } from '@vue/composition-api'; | ||
|
||
export default function useResizeObserver( | ||
container: Ref<HTMLElement>, | ||
callback: (data: [ResizeObserverEntry]) => void, | ||
callback: (data: ResizeObserverEntry[]) => void, | ||
) { | ||
const isSupport = window && window.ResizeObserver; | ||
// unit tests do not need any warn console; too many warns influence focusing on more important log info | ||
if (!isSupport) return; | ||
|
||
let containerObserver: ResizeObserver = null; | ||
|
||
const observeContainer = () => { | ||
if (!container || !container.value || !window || !window.ResizeObserver) { | ||
containerObserver?.unobserve(container.value); | ||
containerObserver?.disconnect(); | ||
} else { | ||
containerObserver = new ResizeObserver(callback); | ||
containerObserver.observe(container.value); | ||
} | ||
const cleanupObserver = () => { | ||
if (!containerObserver) return; | ||
containerObserver.unobserve(container.value); | ||
containerObserver.disconnect(); | ||
containerObserver = null; | ||
}; | ||
|
||
onMounted(() => { | ||
observeContainer(); | ||
}); | ||
const addObserver = (el: HTMLElement) => { | ||
containerObserver = new ResizeObserver(callback); | ||
containerObserver.observe(el); | ||
}; | ||
|
||
if (container) { | ||
watch( | ||
container, | ||
(el) => { | ||
cleanupObserver(); | ||
el && addObserver(el); | ||
}, | ||
{ immediate: true, flush: 'post' }, | ||
); | ||
} | ||
|
||
onBeforeUnmount(() => { | ||
containerObserver?.unobserve(container.value); | ||
containerObserver?.disconnect(); | ||
cleanupObserver(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters