Skip to content

Commit

Permalink
refactor: add data-modalopen attribute to Modal
Browse files Browse the repository at this point in the history
  • Loading branch information
vickonrails committed May 21, 2021
1 parent 017b852 commit 8c9a6d5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/components/modal/modal.tsx
Expand Up @@ -27,6 +27,7 @@ const Modal: FC<ModalProps> = ({
open={open}
{...props}
className={_className}
data-modalopen={open ? true : null}
>
{children}
</StyledModal>
Expand All @@ -50,7 +51,8 @@ interface PrimitiveModalProps {
/**
* onClose - function to execute while closing the Dialog
*/
onClose: (item: false) => void

onClose?: (item: false) => void

/**
* unmount - controls if the Dialog should be unmounted or hidden when closed
Expand Down
47 changes: 47 additions & 0 deletions src/components/modal/readme.md
@@ -0,0 +1,47 @@
# Modals

Renders a select for the user to choose from a range of options

## Quick Use

```jsx
import { Select } from 'avocado-ui'
const [name, setName] = useState('')

const genderOptions = [
{ value: 'male', displayText: 'Male' },
{ value: 'female', displayText: 'Female' }
]

const App: FC = () => (
<Select
onChange={(e) => setState(e.target.value)}
placeholder='Placeholder content'
selectOptions={genderOptions}
/>
)
```

## Props

| property | description | type | default |
| ------------ | -------------------------------------------------------------------------------------------------------------- | ----------- | ------- |
| open | sets the state of the Dialog. Whether the Dialog is open or not. | `boolean` | `false` |
| onClose | function to execute while closing the Dialog | () => void | = |
| unmount | controls if the Dialog should be unmounted or hidden when closed | `boolean` | `blue` |
| as | specifies the html element the component should be rendered as | JSX.Element | `div` |
| initialFocus | control the element that receives focus once the modal is open. Only elements in the tab order can be focused. | React.Ref | `null` |

## Todo

- [x] open
- [x] onClose
- [x] unmount
- [x] as
- [x] initialFocus

## Test Suites

- [x] Modal renders correctly
- [ ] Modal traps focus
- [ ] Modal is active when `open` prop is set to true
3 changes: 2 additions & 1 deletion src/components/modal/title.tsx
Expand Up @@ -28,7 +28,8 @@ interface ModalTitleProps extends HTMLAttributes<HTMLElement> {
/**
* as - specifies the html element the component should be rendered as
*/
as: ElementType<any>

as?: ElementType<any>
}

const StyledTitle = styled<any>(Title)`
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Expand Up @@ -8,7 +8,7 @@
"serve": "gatsby serve"
},
"dependencies": {
"@avocado-ui/react": "^0.1.15",
"@avocado-ui/react": "^0.1.18",
"@emotion/react": "^11.1.5",
"@emotion/styled": "^11.3.0",
"gatsby": "^2.15.18",
Expand Down

0 comments on commit 8c9a6d5

Please sign in to comment.