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

Allow Modal to keep open by adding preventHideOnOutsideClick property #1617

Merged

Conversation

yangwooseong
Copy link
Collaborator

Self Checklist

  • I wrote a PR title in English and added an appropriate label to the PR.
  • I wrote the commit message in English and to follow the Conventional Commits specification.
  • I added the changeset about the changes that needed to be released. (or didn't have to)
  • I wrote or updated documentation related to the changes. (or didn't have to)
  • I wrote or updated tests related to the changes. (or didn't have to)
  • I tested the changes in various browsers. (or didn't have to)
    • Windows: Chrome, Edge, (Optional) Firefox
    • macOS: Chrome, Edge, Safari, (Optional) Firefox

Related Issue

Summary

  • preventHideOnOutsideClick 속성을 Modal 컴포넌트 인터페이스에 추가해서, 모달 밖을 클릭해도 모달이 닫히지 않게 할 수 있도록 합니다.

Details

  • radix-ui 에서 제공하는 Dialog.ContentonPointerDownOutside 콜백에서 이벤트 전파를 막는 것으로 구현하였습니다.

Breaking change? (Yes/No)

  • No

References

@yangwooseong yangwooseong added the enhancement Issues or PR related to making existing features better label Sep 11, 2023
@yangwooseong yangwooseong self-assigned this Sep 11, 2023
@changeset-bot
Copy link

changeset-bot bot commented Sep 11, 2023

🦋 Changeset detected

Latest commit: fb05843

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@channel.io/bezier-react Minor
bezier-figma-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link

codecov bot commented Sep 11, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01% 🎉

Comparison is base (842c80b) 87.00% compared to head (fb05843) 87.02%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1617      +/-   ##
==========================================
+ Coverage   87.00%   87.02%   +0.01%     
==========================================
  Files         281      281              
  Lines        3879     3884       +5     
  Branches      817      820       +3     
==========================================
+ Hits         3375     3380       +5     
  Misses        430      430              
  Partials       74       74              
Files Changed Coverage Δ
...r-react/src/components/Modals/Modal/Modal.types.ts 100.00% <ø> (ø)
...react/src/components/Modals/Modal/ModalContent.tsx 93.75% <100.00%> (+1.15%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 11, 2023

Chromatic Report

🚀 Congratulations! Your build was successful!

Comment on lines 81 to 90
onPointerDownOutside={(e) => {
if (preventHideOnOutsideClick) {
e.preventDefault()
}
}}
>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/radix-ui/primitives/blob/28bebf2c6992d056244845c898abeff45dec2871/packages/react/alert-dialog/src/AlertDialog.tsx#L135-L136

radix-ui AlertDialog를 참고: onInteractOutside 이벤트도 preventDefault 처리되면 좋을 거 같습니다.

  • preventInteractOutside ..? 기존 이름이 동작을 더 구체적으로 나타내서 좋긴 한 거 같은데 말이죠

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preventInteractOutside 라 하면 이게 false 일 때 모달 밖에 있는 버튼과 interact 가능하다는 의미로 받아들여지지 않을까요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그럴 수 있을 거 같고, interact outside 라면 hide on outside click -> interact outside 로 생각을 2단계 거쳐야하는 느낌이라 처음에 작성해주신 속성명이 더 좋은 거 같아요

@@ -40,6 +41,7 @@ export const ModalContent = forwardRef(function ModalContent({
...rest
}: ModalContentProps, forwardedRef: React.Ref<HTMLDivElement>) {
const [contentContainer, setContentContainer] = useState<HTMLElement>()
const preventHideOnOutsideClick = useModalContext()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ModalContent 의 속성으로 전달해줘도 되지 않을까요? Modal 의 컨텍스트로 전달해주신 이유가 궁금합니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모달이 열리고 닫히는 동작을 제어하는 속성이라서 모달의 상태나 핸들러(show, onShow 등등)과 같은 곳에 위치하는게 적절할 것 같았습니다

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DialogPrimitive 의 인터페이스를 따르는 게 전체적인 일관성에 있어서 더 좋지 않을까 생각했어요

Copy link
Contributor

@sungik-choi sungik-choi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인터랙션 테스트 추가 부탁드립니다!

Comment on lines 177 to 185
it('should keep modal open when the user clicks outside of the modal if preventHideOnOutsideClick property is true', async () => {
const { queryByRole, container } = renderOpenedModal({
modalProps: {
preventHideOnOutsideClick: true,
defaultShow: true,
},
})
await user.click(container)
expect(queryByRole('dialog')).toBeInTheDocument()
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 81 to 90
onPointerDownOutside={(e) => {
if (preventHideOnOutsideClick) {
e.preventDefault()
}
}}
>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그럴 수 있을 거 같고, interact outside 라면 hide on outside click -> interact outside 로 생각을 2단계 거쳐야하는 느낌이라 처음에 작성해주신 속성명이 더 좋은 거 같아요

@yangwooseong yangwooseong merged commit 3c3a9fd into channel-io:main Sep 14, 2023
6 checks passed
@yangwooseong yangwooseong deleted the feat/modal-hide-on-blur-property branch September 14, 2023 03:02
sungik-choi pushed a commit that referenced this pull request Sep 18, 2023
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @channel.io/bezier-react@1.13.0

### Minor Changes

- Add `preventHideOnOutsideClick` property to `Modal` component
([#1617](#1617)) by
@yangwooseong

### Patch Changes

- Fixes an issue where the height of `TextArea` component is not
specified correctly. Modify the build settings to match the package.json
exports fields change in 8.5.0 of `react-textarea-autosize`.
([#1637](#1637)) by
@sungik-choi

- Add `ProgressBarSize`, `ProgressBarVariant` string literal type and
deprecate enum
([#1595](#1595)) by
@Dogdriip

## bezier-figma-plugin@0.4.1

### Patch Changes

-   Updated dependencies
    -   @channel.io/bezier-react@1.13.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issues or PR related to making existing features better
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Support title, subtitle, closeIcon in ModalHeader
2 participants