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

feat(kpop): refactor using floating ui [KHCP-11957] #2204

Merged
merged 44 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8128d44
feat(kpop): refactor using floating ui [KHCP-11957]
portikM Jun 3, 2024
d738385
fix(kpop): refactor using @floating-ui/vue [KHCP-11957]
portikM Jun 4, 2024
3a011b3
fix(kpop): trigger and positioning fixes [KHCP-11957]
portikM Jun 4, 2024
da59aa8
fix: ts
portikM Jun 4, 2024
9f7da5e
fix(*): kpop selectors and placements [KHCP-11957]
portikM Jun 4, 2024
9918fdc
fix(kpop): auto placement [KHCP-11957]
portikM Jun 4, 2024
2df98aa
fix(*): kpop styles and placements [KHCP-11957]
portikM Jun 4, 2024
8caeb06
test(kmultiselect, ktooltip): fix component tests [KHCP-11957]
portikM Jun 4, 2024
a9429d4
fix(*): update kpop usage [KHCP-11957]
portikM Jun 4, 2024
67150c0
docs(popover): update component docs [KHCP-11957]
portikM Jun 4, 2024
0568a73
docs: update migration doc [KHCP-11957]
portikM Jun 4, 2024
fb5269f
fix(kdatetimepicker): update kpop usage [KHCP-11957]
portikM Jun 4, 2024
30c38b5
Merge branch 'alpha' into feat/khcp-11957-popper-js-replacement
portikM Jun 4, 2024
9019040
fix(*): address pr feedback [KHCP-11957]
portikM Jun 5, 2024
e14b25f
fix(kpop): position absolute placement [KHCP-11957]
portikM Jun 5, 2024
88d2692
fix(kdatetimepicker): fix popover styling [KHCP-11957]
portikM Jun 5, 2024
aaa8767
fix(*): misc fixes [KHCP-11957]
portikM Jun 5, 2024
e9b31e5
fix(kpop): misc fixes [KHCP-11957]
portikM Jun 5, 2024
2d70302
fix(kdropdown): minor styling fix [KHCP-11957]
portikM Jun 5, 2024
eb5d4cf
Merge branch 'alpha' into feat/khcp-11957-popper-js-replacement
portikM Jun 5, 2024
f4b1d32
fix(kpop): auto update logic [KHCP-11957]
portikM Jun 5, 2024
4164ae1
docs(popover): default slot note [KHCP-11957]
portikM Jun 5, 2024
27ea6e4
fix(kpop): add comment [KHCP-11957]
portikM Jun 5, 2024
c254879
fix(kpop): cleanup auto updates [KHCP-11957]
portikM Jun 5, 2024
d9bd325
fix(kpop): popover flip and shift [KHCP-11957]
portikM Jun 5, 2024
1051006
test(ktooltip): remove invoke css [KHCP-11957]
portikM Jun 5, 2024
a71be92
fix(kpop): popover element width [KHCP-11957]
portikM Jun 5, 2024
81a15c8
fix(kpop): fix resize observer loop issue [KHCP-11957]
portikM Jun 5, 2024
04dd28a
fix(kpop): floating ui middleware magic [KHCP-11957]
portikM Jun 6, 2024
00e5841
fix(kpop): remove position fixed prop [KHCP-11957]
portikM Jun 6, 2024
529871d
Merge branch 'alpha' into feat/khcp-11957-popper-js-replacement
portikM Jun 6, 2024
0918c78
fix: lint:fix
portikM Jun 6, 2024
a28339d
Merge branch 'alpha' into feat/khcp-11957-popper-js-replacement
portikM Jun 6, 2024
41ea59f
test(kdropdown): fix component test [KHCP-11957]
portikM Jun 6, 2024
f5d6e09
fix: apply pr feedback
portikM Jun 6, 2024
f5215f5
fix(*): remove position fixed prop [KHCP-11957]
portikM Jun 6, 2024
8c3982a
fix(kpop): minor fix [KHCP-11957]
portikM Jun 6, 2024
f87058c
fix(kpop): placement backwards compitability [KHCP-11957]
portikM Jun 7, 2024
0964c46
Merge branch 'alpha' into feat/khcp-11957-popper-js-replacement
portikM Jun 7, 2024
1faa5bf
fix(kbadge, kmultiselect): fix truncated item jumpy bug [KHCP-11957]
portikM Jun 7, 2024
abdcf51
fix(kpop): popover trigger wrapper display [KHCP-11957]
portikM Jun 7, 2024
5610c90
fix(kdropdown): minor fix [KHCP-11957]
portikM Jun 10, 2024
3afdb0c
fix: resolve conflicts
portikM Jun 10, 2024
db1b459
fix: misc fix [KHCP-11957]
portikM Jun 10, 2024
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/components/KDateTimePicker/KDateTimePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
hide-close-icon
:placement="popoverPlacement"
position-fixed
width="max-content"
width="auto"
@close="state.popoverOpen = false"
@open="state.popoverOpen = true"
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/KPop/KPop.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('KPop', () => {
},
})
cy.get('.slottedEl').click()
cy.get('.popover').invoke('width').should('eq', width)
cy.get('.popover .popover-container').invoke('width').should('eq', width)
})

it('renders with correct title', () => {
Expand Down
43 changes: 31 additions & 12 deletions src/components/KPop/KPop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
class="popover"
:class="popoverClassesObj"
role="dialog"
:style="popoverStyle"
:style="floatingStyles"
:x-placement="calculatedPlacement"
>
<div class="popover-container">
<div
class="popover-container"
:style="popoverStyles"
>
<button
v-if="!hideCloseIcon"
ref="popoverCloseButton"
Expand Down Expand Up @@ -82,7 +85,7 @@
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount, computed, watch } from 'vue'
import type { PropType } from 'vue'
import { useFloating, autoUpdate, autoPlacement, flip, shift } from '@floating-ui/vue'
import { useFloating, autoUpdate, autoPlacement, flip, shift, size } from '@floating-ui/vue'
import type { PopPlacements, PopTrigger } from '@/types'
import { PopPlacementsArray, PopTriggerArray } from '@/types'
import { v4 as uuid4 } from 'uuid'
Expand Down Expand Up @@ -135,7 +138,7 @@ const props = defineProps({
},
maxWidth: {
type: String,
default: '100vw', // need to set for Floating UI to work properly
default: 'auto',
},
maxHeight: {
type: String,
Expand Down Expand Up @@ -221,12 +224,11 @@ const clickHandler = (event: Event) => {
}
}

const popoverStyle = computed(() => {
const popoverStyles = computed(() => {
return {
width: props.width === 'auto' ? 'max-content' : getSizeFromString(props.width), // need to set to max-content for Floating UI to work properly
width: getSizeFromString(props.width),
maxWidth: getSizeFromString(props.maxWidth),
maxHeight: getSizeFromString(props.maxHeight),
...floatingStyles.value,
}
})

Expand All @@ -235,8 +237,25 @@ const popoverClassesObj = computed(() => [props.popoverClasses, { 'hide-caret':
const popoverPlacement = computed((): PopPlacements => props.positionFixed ? props.placement : 'top')

const { floatingStyles, placement: calculatedPlacement, update: updatePosition } = useFloating(popoverTrigger, popoverElement, {
...(popoverPlacement.value === 'auto' ? { middleware: [autoPlacement()] } : { placement: popoverPlacement.value, middleware: [flip(), shift()] }),
...(popoverPlacement.value === 'auto' && { middleware: [autoPlacement()] }), // when placement is auto just use autoPlacement middleware
...(popoverPlacement.value !== 'auto' && {
placement: popoverPlacement.value,
middleware: [
flip(),
shift(),
size({
apply({ elements, availableHeight }) {
requestAnimationFrame(() => {
Object.assign(elements.floating.style, {
maxHeight: `${availableHeight}px`,
})
})
adamdehaven marked this conversation as resolved.
Show resolved Hide resolved
},
}),
],
}),
strategy: props.positionFixed ? 'fixed' : 'absolute',
transform: false,
})

const floatingUpdates = ref<Function | null>(null)
Expand Down Expand Up @@ -270,9 +289,7 @@ onMounted(() => {
// start the auto updates for the popover position
// autoUpdate cleanup function
// docs: https://floating-ui.com/docs/autoUpdate#usage
floatingUpdates.value = autoUpdate(popoverTrigger.value, popoverElement.value, updatePosition, {
elementResize: false, // fixes ResizeObserver loop issue
})
floatingUpdates.value = autoUpdate(popoverTrigger.value, popoverElement.value, updatePosition)
}
})

Expand Down Expand Up @@ -351,6 +368,9 @@ $kPopCaretOffset: 16px;
}

.popover {
// need max-width: 100vw; and width: max-content; for Floating UI to work properly
max-width: 100vw;
width: max-content;
z-index: v-bind('zIndex');

// need to wrap popover content in a container because we cannot set position: relative; as that will break the floating-ui positioning
Expand All @@ -363,7 +383,6 @@ $kPopCaretOffset: 16px;
flex-direction: column;
font-family: var(--kui-font-family-text, $kui-font-family-text);
gap: var(--kui-space-40, $kui-space-40);
max-width: none;
padding: var(--kui-space-60, $kui-space-60);
position: relative;
text-align: left;
Expand Down
2 changes: 1 addition & 1 deletion src/components/KTooltip/KTooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:popover-timeout="100"
:position-fixed="positionFixed"
trigger="hover"
width="max-content"
width="auto"
:z-index="zIndex"
>
<slot />
Expand Down
1 change: 0 additions & 1 deletion src/composables/useUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ export default function useUtilities() {
*/
const getSizeFromString = (sizeStr: string): string => {
return sizeStr === 'auto' ||
sizeStr === 'max-content' ||
sizeStr.endsWith('%') ||
sizeStr.endsWith('vw') ||
sizeStr.endsWith('vh') ||
Expand Down