Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 72cfb30

Browse files
committed
feat(utils): add a use getSelector utility
1 parent f074826 commit 72cfb30

File tree

15 files changed

+362
-210
lines changed

15 files changed

+362
-210
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"ts-jest": "^26.5.0",
114114
"ts-node": "^9.0.0",
115115
"typescript": "^4.1.3",
116-
"vite": "2.1.5",
116+
"vite": "^2.2.3",
117117
"vite-plugin-components": "^0.8.3",
118118
"vite-plugin-pages": "^0.9.2",
119119
"vitepress": "^0.12.0",

packages/c-focus-lock/examples/with-focus-lock-component.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
@deactivate="handleDeactivate"
1616
:allow-outside-click="false"
1717
:initial-focus-ref="() => initialFocusRef"
18-
:final-focus-ref="() => finalFocusRef"
1918
#default="{ hasFocus, deactivate }"
2019
pos="relative"
2120
v-if="isActive"

packages/c-focus-lock/examples/with-focus-lock-hook.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const {
8080
} = useFocusLock({
8181
escapeDeactivates: false,
8282
delayInitialFocus: true,
83+
immediate: true,
8384
})
8485
8586
const activate = async () => {

packages/c-modal/src/c-modal.ts

Lines changed: 25 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
watch,
2323
withDirectives,
2424
unref,
25+
watchEffect,
2526
} from 'vue'
2627
import {
2728
chakra,
@@ -212,19 +213,18 @@ export const CModal = defineComponent({
212213
setup(props, { slots, attrs, emit }) {
213214
const closeModal = () => {
214215
emit('update:is-open', false)
215-
console.log('CLOSING MODAL =============')
216216
}
217217

218218
const handleEscape = (event: KeyboardEvent) => {
219219
emit('escape', event)
220220
}
221221

222222
const styles = useMultiStyleConfig('Modal', mergeProps(props, attrs))
223-
const modalOptions = {
223+
const modalOptions = reactive({
224224
...toRefs(reactive(props)),
225225
closeModal,
226226
handleEscape,
227-
}
227+
})
228228
// @ts-expect-error
229229
const modal = useModal(modalOptions)
230230

@@ -246,55 +246,16 @@ export const CModal = defineComponent({
246246
},
247247
})
248248

249-
export const CModalFocusScope = defineComponent({
250-
name: 'CModalFocusScope',
251-
setup(_, { attrs, slots }) {
252-
const {
253-
isOpen,
254-
initialFocusRef,
255-
returnFocusOnClose,
256-
finalFocusRef,
257-
blockScrollOnMount,
258-
} = useModalContext()
259-
260-
const finalFocusEl = computed(() =>
261-
typeof finalFocusRef?.value === 'function'
262-
? finalFocusRef.value()
263-
: finalFocusRef?.value
264-
)
265-
266-
return () => {
267-
return h(
268-
CFocusLock,
269-
{
270-
finalFocusEl: finalFocusEl.value,
271-
...attrs,
272-
},
273-
() => [
274-
h(
275-
CScrollLock,
276-
{
277-
enabled: blockScrollOnMount?.value,
278-
},
279-
() => slots.default?.()
280-
),
281-
]
282-
)
283-
}
284-
},
285-
})
286-
287249
/**
288250
* ModalContent is used to group modal's content. It has all the
289251
* necessary `aria-*` properties to indicate that it is a modal
290252
*/
291253
export const CModalContent = defineComponent({
292254
name: 'CModalContent',
293255
inheritAttrs: false,
294-
emits: ['click'],
295-
setup(_, { attrs, slots }) {
296-
const context = useModalContext()
297-
256+
emits: ['click', 'mousedown', 'keydown'],
257+
setup(_, { attrs, slots, emit }) {
258+
const { dialogContainerProps, dialogProps } = unref(useModalContext())
298259
const styles = useStyles()
299260

300261
const dialogContainerStyles = computed<SystemStyleObject>(() => ({
@@ -317,61 +278,25 @@ export const CModalContent = defineComponent({
317278
}))
318279

319280
return () => {
320-
return withDirectives(
321-
h(
322-
chakra('div', {
323-
label: 'modal__content-container',
324-
__css: dialogContainerStyles.value,
325-
}),
326-
context.value.dialogContainerProps.value,
327-
() => [
328-
h(
329-
CFocusLock,
330-
{
331-
allowOutsideClick: true,
332-
initialFocusRef: context.value.initialFocusRef?.value,
333-
finalFocusRef: context.value.finalFocusRef?.value,
334-
restoreFocus: context.value.returnFocusOnClose?.value,
335-
},
336-
() => [
337-
withDirectives(
338-
h(
339-
chakra('section', {
340-
__css: dialogStyles.value,
341-
label: 'modal__content',
342-
}),
343-
{
344-
...attrs,
345-
...context.value.dialogProps.value,
346-
},
347-
slots
348-
),
349-
[
350-
[
351-
MotionDirective,
352-
{
353-
initial: {
354-
scale: 0.5,
355-
opacity: 0,
356-
},
357-
enter: {
358-
scale: 1,
359-
opacity: 1,
360-
translateY: 0,
361-
},
362-
leave: {
363-
scale: 0.5,
364-
opacity: 0,
365-
},
366-
},
367-
],
368-
]
369-
),
370-
]
371-
),
372-
]
373-
),
374-
[[BodyScrollLockDirective, context.value.blockScrollOnMount?.value]]
281+
return h(
282+
chakra('div', {
283+
label: 'modal__content-container',
284+
__css: dialogContainerStyles.value,
285+
}),
286+
dialogContainerProps.value({ emit }),
287+
() => [
288+
h(
289+
chakra('section', {
290+
__css: dialogStyles.value,
291+
label: 'modal__content',
292+
}),
293+
{
294+
...attrs,
295+
...dialogProps.value({ emit }),
296+
},
297+
slots
298+
),
299+
]
375300
)
376301
}
377302
},

0 commit comments

Comments
 (0)