-
Notifications
You must be signed in to change notification settings - Fork 7
Fix FloatingAssistant Position #1046
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
7b0db1f
ead935b
26eb7ac
1eef482
bfb95d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,27 +1,79 @@ | ||||||||||||||||||||||||||||||
| import { createPopper } from '@popperjs/core'; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export default (el, biding) => { | ||||||||||||||||||||||||||||||
| let target = ''; | ||||||||||||||||||||||||||||||
| let popoverElement = ''; | ||||||||||||||||||||||||||||||
| let modifiers = biding.modifiers; | ||||||||||||||||||||||||||||||
| let position = biding.arg; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| target = document.querySelector(`[id='${biding.value}']`); | ||||||||||||||||||||||||||||||
| popoverElement = document.querySelector(`[id='${el.id}']`); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| createPopper(target, popoverElement, { | ||||||||||||||||||||||||||||||
| placement: position, | ||||||||||||||||||||||||||||||
| modifiers: [ | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| name: 'offset', | ||||||||||||||||||||||||||||||
| options: { | ||||||||||||||||||||||||||||||
| offset: [0, -4], | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| name: 'flip', | ||||||||||||||||||||||||||||||
| enabled: !!modifiers.flip, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| let popperInstance = null; | ||||||||||||||||||||||||||||||
| let observer = null; | ||||||||||||||||||||||||||||||
| let scrollHandler = null; | ||||||||||||||||||||||||||||||
| let resizeHandler = null; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const CdsFloatify = { | ||||||||||||||||||||||||||||||
| mounted: (el, binding) => { | ||||||||||||||||||||||||||||||
| const target = document.querySelector(`[id='${binding.value}']`); | ||||||||||||||||||||||||||||||
| const popoverElement = document.querySelector(`[id='${el.id}']`); | ||||||||||||||||||||||||||||||
| const modifiers = binding.modifiers; | ||||||||||||||||||||||||||||||
| const position = binding.arg; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if (target && popoverElement) { | ||||||||||||||||||||||||||||||
| popperInstance = createPopper(target, popoverElement, { | ||||||||||||||||||||||||||||||
| placement: position, | ||||||||||||||||||||||||||||||
| modifiers: [ | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| name: 'offset', | ||||||||||||||||||||||||||||||
| options: { | ||||||||||||||||||||||||||||||
| offset: [0, -4], | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| name: 'flip', | ||||||||||||||||||||||||||||||
| enabled: !!modifiers.flip, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| observer = new MutationObserver(() => { | ||||||||||||||||||||||||||||||
| if (popperInstance) { | ||||||||||||||||||||||||||||||
| popperInstance.update(); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| observer.observe(document.body, { | ||||||||||||||||||||||||||||||
| childList: true, | ||||||||||||||||||||||||||||||
| subtree: true, | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. observar observe apenas o elemento target ou use |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| scrollHandler = () => { | ||||||||||||||||||||||||||||||
| if (popperInstance) { | ||||||||||||||||||||||||||||||
| popperInstance.update(); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| resizeHandler = () => { | ||||||||||||||||||||||||||||||
| if (popperInstance) { | ||||||||||||||||||||||||||||||
| popperInstance.update(); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| window.addEventListener('scroll', scrollHandler); | ||||||||||||||||||||||||||||||
| window.addEventListener('resize', resizeHandler); | ||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adicione
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| beforeUnmount: () => { | ||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||
| if (popperInstance) { | ||||||||||||||||||||||||||||||
| popperInstance.destroy(); | ||||||||||||||||||||||||||||||
| popperInstance = null; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| if (observer) { | ||||||||||||||||||||||||||||||
| observer.disconnect(); | ||||||||||||||||||||||||||||||
| observer = null; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if(scrollHandler) { | ||||||||||||||||||||||||||||||
| window.removeEventListener('scroll', scrollHandler); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if(resizeHandler) { | ||||||||||||||||||||||||||||||
| window.removeEventListener('resize', resizeHandler); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. precisa remover listeners com as mesmas opções usadas no
Suggested change
|
||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export default CdsFloatify; | ||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variáveis globais causam conflitos entre múltiplas instâncias - se houver mais de um
FloatingAssistantna página, eles vão sobrescrever as instâncias uns dos outrosarmazene no próprio elemento como em
cdstip.js:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jules