Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
e2e66fa
build: added templates for component
codebender828 Apr 3, 2021
163b556
refactor: create focus lock hook
codebender828 Apr 3, 2021
576852c
feat: focus trap hook implemented
codebender828 Apr 3, 2021
a435a69
refactor: move focus-lock to package
codebender828 Apr 4, 2021
fe321ca
test(focus-lock): addted tests for focus-lock componentS
codebender828 Apr 7, 2021
78197f7
feat(wip): focus lock component
codebender828 Apr 7, 2021
996f91d
docs(focus-lock): add focus-lock docs
codebender828 Apr 7, 2021
92afc35
build(focus-lock): update types and dependencies
codebender828 Apr 7, 2021
14eb28a
chore: fix deps
codebender828 Apr 7, 2021
aef799c
chore: remove second focus-lock
codebender828 Apr 7, 2021
596ce48
chore: remove second focus-lock
codebender828 Apr 7, 2021
bff3492
Merge pull request #55 from chakra-ui/feat/focus-lock
codebender828 Apr 7, 2021
bdcf06a
Merge branch 'develop' of https://github.com/chakra-ui/chakra-ui-vue-…
codebender828 Apr 7, 2021
f9795d5
chore: fix packages dependencies
codebender828 Apr 7, 2021
2d8d7cd
feat(hooks): add use-id hook
codebender828 Apr 7, 2021
27a2ecc
test: add test for useId
codebender828 Apr 7, 2021
0ed6db3
feat(modal): create modal context props
codebender828 Apr 7, 2021
0932896
feat(moda): create use-aria-hidden hook
codebender828 Apr 8, 2021
2fd7c07
feat(utils): create useDOMRef hook
codebender828 Apr 8, 2021
7c11769
feat(modal): create modal overlay
codebender828 Apr 8, 2021
c744af2
feat(modal): create modal focus scope
codebender828 Apr 8, 2021
9dfcf6d
feat: create scroll lock
codebender828 Apr 8, 2021
152ee8b
feat(scroll-lock): create body scroll lock component, directive and hook
codebender828 Apr 8, 2021
deba639
refactor(scroll-lock): use directive locally
codebender828 Apr 8, 2021
0ad4c1e
feat(modal): modal content
codebender828 Apr 8, 2021
7b60e1d
fix: prevent emit value with close event
codebender828 Apr 8, 2021
f48151f
feat: transitions for modal
codebender828 Apr 8, 2021
4f84317
feat(motion): create motion package and transition modal
codebender828 Apr 8, 2021
4df1c90
chore: fix motion dependencies
codebender828 Apr 8, 2021
3b8ba06
fix(focus-lock): fix focus lock component and hook
codebender828 Apr 14, 2021
980d708
test(docs): update focus lock tests descriptions. skipping in prefere…
codebender828 Apr 14, 2021
10b6026
chore: more preogress debugging focus lock
codebender828 Apr 14, 2021
3e2a200
Merge branch 'develop' of https://github.com/chakra-ui/chakra-ui-vue-…
codebender828 Apr 15, 2021
4e890c9
fix(use-modal): provide computed variables
codebender828 Apr 28, 2021
f074826
feat(modal): update theme and add modal close button
codebender828 Apr 29, 2021
72cfb30
feat(utils): add a use getSelector utility
codebender828 Apr 30, 2021
662da3a
fix(modal): fallback tp return focus on disable
codebender828 Apr 30, 2021
b027c4b
fix(aria-hidden): undo aria-hidden on unmount modal
codebender828 May 1, 2021
161478b
fix: use aria-hidden types
codebender828 May 1, 2021
ef58bfe
feat(wip): useDialogTransitions for dialog elements
codebender828 May 1, 2021
24c1f4a
fix: create modal transitions
codebender828 May 2, 2021
8a9106c
refactor: remove dialog transitions
codebender828 May 2, 2021
fb153dc
feat: block scroll on mount
codebender828 May 2, 2021
fe2e1ac
test(focus-lock): update focus-lock hook tests
codebender828 May 2, 2021
7517ca5
fix(focus-lock): update types for focus lock component
codebender828 May 2, 2021
9b79128
test: update tests for scroll lock
codebender828 May 4, 2021
1bb327c
build: update build config for ci test
codebender828 May 4, 2021
24c0fbd
test: fix all test warning
codebender828 May 4, 2021
b05cde3
Merge branch 'develop' of github.com:chakra-ui/chakra-ui-vue-next int…
codebender828 May 30, 2021
4ff56c4
test(modal): add cypress tests for modal
codebender828 Jun 16, 2021
6ec7b88
chore: cleanup unused files
codebender828 Jun 16, 2021
576a7f1
chore: release minor changeset
codebender828 Jun 16, 2021
2673707
fix: resolve merge conflicts
codebender828 Jun 16, 2021
718bc68
fix: use bare string for transition names
codebender828 Jun 16, 2021
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
Binary file modified .DS_Store
Binary file not shown.
31 changes: 31 additions & 0 deletions .changeset/rare-ads-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
'@chakra-ui/c-accordion': minor
'@chakra-ui/c-alert': minor
'@chakra-ui/c-button': minor
'@chakra-ui/c-code': minor
'@chakra-ui/c-flex': minor
'@chakra-ui/c-focus-lock': minor
'@chakra-ui/c-icon': minor
'@chakra-ui/c-modal': minor
'@chakra-ui/c-motion': minor
'@chakra-ui/c-popper': minor
'@chakra-ui/c-portal': minor
'@chakra-ui/c-reset': minor
'@chakra-ui/c-scroll-lock': minor
'@chakra-ui/c-spinner': minor
'@chakra-ui/c-visually-hidden': minor
'@chakra-ui/vue-next': minor
'@chakra-ui/vue-layout': minor
'@chakra-ui/vue-theme': minor
'@chakra-ui/vue-theme-tools': minor
'@chakra-ui/vue-utils': minor
'@chakra-ui/vue-a11y': minor
'@chakra-ui/vue-composables': minor
'@chakra-ui/vue-auto-import': minor
'@chakra-ui/vue-docs': minor
---

- Adds Modal component
- Adds FocusLock composable, directive and component
- Adds ScrollLock composable, directive and component
- Improves TSX support
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ dist
# At the time of writing this, I could not find any helpful
# documentation for adding ESLint for Vue 3 projects running on Vite.
# For this reason, we ignore the playground directory.
playground
playground
snapshots.js
9 changes: 9 additions & 0 deletions _templates/generator/component/component.ts.ejs.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
---
to: packages/<%=h.changeCase.paramCase(name)%>/src/<%=h.changeCase.paramCase(name)%>.ts
---
/**
* Hey! Welcome to @chakra-ui/vue-next <%= h.changeCase.pascalCase(name) %>
*
* <%=h.changeCase.sentence(description)%>
*
* @see Docs https://next.vue.chakra-ui.com/<%=h.changeCase.paramCase(name)%>
* @see Source https://github.com/chakra-ui/chakra-ui-vue-next/blob/master/packages/<%=h.changeCase.paramCase(name)%>/src/<%=h.changeCase.paramCase(name)%>/<%=h.changeCase.paramCase(name)%>.ts
* @see WAI-ARIA https://www.w3.org/TR/wai-aria-practices-1.2
*/

import { h, defineComponent, PropType } from 'vue'
import { chakra, DOMElements } from '@chakra-ui/vue-system'
Expand Down
4 changes: 2 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ const testConfig = {
[
'@babel/preset-env',
{
targets: { node: true },
targets: { node: 'current' },
},
],
],
plugins: ['@vue/babel-plugin-jsx'],
plugins: ['@vue/babel-plugin-jsx', '@babel/plugin-transform-runtime'],
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ function getSetupSidebar() {
{
text: 'Composables',
children: [
{ text: 'usePopper', link: '/composables/use-popper' }
{ text: 'usePopper', link: '/composables/use-popper' },
{ text: 'useFocusLock', link: '/composables/use-focus-lock' }
]
}
]
Expand Down
110 changes: 110 additions & 0 deletions docs/composables/use-focus-lock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# useFocusLock

The **`useFocusLock`** hook is an internal hook for Chakra UI Vue used to encapsulate `focus-trap` into an extendable composable hook.

This allows us to compose the behaviour required for focus trapping accessible dialogs and modals into a single hook and can be extended as a component

## Import

```bash
import { useFocusLock } from "@chakra-ui/c-focus-lock"
```

This composable accepts options to modify the positioning fo the popover as well as the modifiers of the popper. It returns an object of properties that can be used to bind the template refs to the popper instance

## Usage

```vue
<template>
<chakra.div
:ref="lock"
p="4"
border="4px dashed"
rounded="lg"
border-color="gray.400"
d="inline-block"
>
<chakra.p mb="2">Inside focus trap</chakra.p>
<c-button @click="options.enabled = true" color-scheme="teal">
Enable focus lock
</c-button>
<c-button :ref="initialFocus" color-scheme="yellow" mx="2"
>Button 2</c-button
>
<c-button color-scheme="blue">Button 3</c-button>
</chakra.div>
</template>

<script lang="ts">
import { useFocusLock, FocusLockOptions } from '@chakra-ui/c-focus-lock'
import { defineComponent, reactive } from 'vue'

export default defineComponent({
setup() {
const options: FocusLockOptions = reactive({
enabled: true,
onActivate: () => {
console.log('focus lock ENABLED')
},
onDeactivate: () => {
console.log('focus lock DEACTIVATED')
},
})

const { lock, initialFocus } = useFocusLock(options)

return {
lock,
options,
initialFocus,
}
},
})
</script>


```

## Props
These are the options for the `usePopper` composable. These properties are similar to the options listed in the [@popperjs/core](https://popper.js.org/docs/v2/) documentation.
```ts
export interface FocusLockOptions {
/**
* Determines whether the focus lock is active or inactive
* @default true
*/
enabled: boolean
/**
* Invoked handler when focus-lock is activated
*/
onActivate?: () => void
/**
* Invoked handler when focus-lock is deactivated
*/
onDeactivate?: () => void
/**
* Invoked handler when focus-lock is activated.
*
* By default, an error will be thrown if the focus lock
* contains no elements in its tab order. With this
* option you can specify a fallback element to
* programmatically receive focus if no other
* tabbable elements are found.
*/
fallbackFocus?: FocusTarget
/**
* Determines whether focus lock is activated when user clicks outside.
* @default true
*/
clickOutsideDeactivates?: boolean | ((e: MouseEvent) => boolean)
persistentFocus?: boolean | ((e: MouseEvent) => boolean)
/**
* Determines whether to return focus to the previously focused element
* before the focus-trap was activated, after the focus trap has been deactivated.
*/
returnFocus?: boolean
preventScroll?: boolean
escapeDeactivates?: boolean
delayInitialFocus?: boolean
}
```
2 changes: 1 addition & 1 deletion docs/guides/component-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ we advice to follow to deliver on the quality expectations.

### General

- Ensure you check the `@chakra-ui/vue-hooks`, and `@chakra-ui/vue-utils` package to be
- Ensure you check the `@chakra-ui/vue-composables`, and `@chakra-ui/vue-utils` package to be
sure we don't already have the hook you're looking to create.
- Leverage existing code, hook, or utils as much as possible.
- Separate component logic from UI by writing hooks, and then writing the
Expand Down
21 changes: 15 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"workspaces": [
"packages/*",
"tooling/*",
"website",
"tests"
"website"
],
"scripts": {
"pkg": "manypkg run",
Expand All @@ -20,7 +19,7 @@
"scaffold": "hygen generator",
"release": "yarn changeset publish",
"build": "lerna run build --no-private --stream",
"dev": "NODE_ENV=development vite serve playground --config ./vite.config.ts",
"dev": "NODE_ENV=development vite serve playground --config ./vite.config.ts --open",
"playground:build": "yarn install && yarn build && yarn bootstrap && NODE_ENV=production vite build playground --config ./vite.config.ts",
"cy:open": "cypress open-ct",
"cy:run": "cypress run-ct --quiet",
Expand Down Expand Up @@ -55,6 +54,7 @@
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/user-event": "^12.6.2",
"@testing-library/vue": "^6.3.4",
"@types/body-scroll-lock": "^2.6.1",
"@types/jest": "^26.0.20",
"@types/jest-axe": "^3.5.1",
"@types/lodash.camelcase": "^4.3.6",
Expand All @@ -70,10 +70,13 @@
"@vue/eslint-config-typescript": "^5.1.0",
"@vuedx/typecheck": "^0.4.1",
"@vuedx/typescript-plugin-vue": "^0.4.1",
"@vueuse/motion": "1.5.4",
"@vueuse/core": "4.9.1",
"@vueuse/integrations": "^4.8.1",
"@vueuse/motion": "^1.5.4",
"aria-hidden": "^1.1.2",
"axe-core": "^4.1.2",
"babel-jest": "^26.6.3",
"body-scroll-lock": "^3.1.5",
"change-case": "^4.1.1",
"chokidar": "^3.5.1",
"concurrently": "^5.3.0",
Expand All @@ -82,6 +85,7 @@
"css-get-unit": "^1.0.1",
"csstype": "^3.0.5",
"dequal": "^2.0.2",
"dom-focus-lock": "^1.0.4",
"esbuild-jest": "^0.4.0",
"eslint": "^7.0.0",
"eslint-config-prettier": "^6.12.0",
Expand All @@ -93,6 +97,7 @@
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-vue": "^7.0.0",
"feather-icons-paths": "^1.0.8",
"focus-trap": "^6.3.0",
"fs-extra": "^9.0.1",
"husky": "^4.3.8",
"hygen": "^6.0.4",
Expand Down Expand Up @@ -124,10 +129,14 @@
"vue3-perfect-scrollbar": "^1.5.5"
},
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.13.15",
"@cypress/snapshot": "^2.1.7",
"@cypress/vite-dev-server": "^1.2.6",
"@cypress/vue": "^3.0.1",
"@cypress/vue": "^3",
"@vue/test-utils": "^2.0.0-rc.6",
"cypress": "^7.2.0"
"cypress": "^7.2.0",
"cypress-commands": "^1.1.0",
"cypress-plugin-tab": "^1.0.5",
"local-cypress": "^1.2.1"
}
}
2 changes: 1 addition & 1 deletion packages/c-alert/examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export * as BaseAlert from './base-alert.vue'
export * as WithAccent from './with-accent.vue'
export * as WithIcon from './with-icon.vue'
export * as WithStatus from './with-status.vue'
export * as WithTitle from './with-title.vue'
export * as WithTitle from './with-title.vue'
21 changes: 9 additions & 12 deletions packages/c-alert/tests/c-alert.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,24 @@ import { CAlert, CAlertDescription, CAlertIcon, CAlertTitle } from '../src'
describe('Alert Examples', () => {
Object.entries(Examples).map(([name, example]) => {
it(`renders ${name} successfully`, () => {
cy.mount(example.default)
.then(() => {})
.checkA11y()
cy.mount(h(() => <example.default></example.default>)).checkA11y()
})
})
})

it('contains the correct role', () => {
cy.mount(Examples.BaseAlert.default)
.then(() => {})
.get('[role=alert]')
.should('exist')
cy.mount(Examples.BaseAlert.default).get('[role=alert]').should('exist')
})

it('renders its children', () => {
cy.mount(
<CAlert data-testid="alert" variant="left-accent" status="info" mb="3">
<CAlertIcon mr="2" />
<CAlertTitle> Info alert </CAlertTitle>
<CAlertDescription> Something just happened </CAlertDescription>
</CAlert>
h(() => (
<CAlert data-testid="alert" variant="left-accent" status="info" mb="3">
<CAlertIcon mr="2" />
<CAlertTitle> Info alert </CAlertTitle>
<CAlertDescription> Something just happened </CAlertDescription>
</CAlert>
))
)
.get('[data-testid=alert]')
.should('contain', 'Info alert')
Expand Down
2 changes: 1 addition & 1 deletion packages/c-button/examples/button-group.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * as WithButtonGroup from './with-button-group.vue'
export * as WithButtonGroup from './with-button-group.vue'
2 changes: 1 addition & 1 deletion packages/c-button/examples/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export * as WithAttachedButtons from './with-attached-buttons.vue'
export * as WithButtonSize from '../examples/with-button-size.vue'
export * as WithButtonIcon from '../examples/with-button-icon.vue'
export * as WithButtonVariants from '../examples/with-button-variants.vue'
export * as WithLoadingStatus from '../examples/with-loading-status.vue'
export * as WithLoadingStatus from '../examples/with-loading-status.vue'
2 changes: 1 addition & 1 deletion packages/c-button/examples/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * as Button from './button'
export * as ButtonGroup from './button-group'
export * as ButtonGroup from './button-group'
1 change: 1 addition & 0 deletions packages/c-button/examples/with-button-variants.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<div>
<c-button mr="3" variant="luxury"> Solid </c-button>
<c-button mr="3" variant="solid" color-scheme="teal"> Solid </c-button>
<c-button mr="3" variant="outline" color-scheme="teal"> Outline </c-button>
<c-button mr="3" variant="ghost" color-scheme="teal"> Ghost </c-button>
Expand Down
25 changes: 14 additions & 11 deletions packages/c-button/src/button-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ const props = {
...vueThemingProps,
}

type ButtonGroupContext = ComputedRef<ThemingProps & {
isDisabled?: boolean
}>
type ButtonGroupContext = ComputedRef<
ThemingProps & {
isDisabled?: boolean
}
>

const [ButtonGroupProvider, useButtonGroup] = createContext<ButtonGroupContext>(
{
Expand All @@ -49,12 +51,14 @@ const CButtonGroup = defineComponent({
name: 'CButtonGroup',
props,
setup(props, { attrs, slots }) {
ButtonGroupProvider(computed(() => ({
size: props.size,
colorScheme: props.colorScheme,
variant: props.variant,
isDisabled: props.isDisabled,
})))
ButtonGroupProvider(
computed(() => ({
size: props.size,
colorScheme: props.colorScheme,
variant: props.variant,
isDisabled: props.isDisabled,
}))
)

const styles = computed(() => {
let groupStyles: SystemStyleObject = {
Expand All @@ -77,9 +81,8 @@ const CButtonGroup = defineComponent({

return groupStyles
})

return () => {

return () => {
return h(
chakra('div', { label: 'button__group' }),
{
Expand Down
Loading