Skip to content

Conversation

@IKEYCY
Copy link
Contributor

@IKEYCY IKEYCY commented Dec 15, 2025

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • The Drawer component now includes a new close-on-press-escape prop that enables automatic drawer closure when the ESC key is pressed. This property is disabled by default and can be individually configured per drawer instance. Users can now leverage this keyboard-based interaction pattern as a familiar way to close drawers.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 15, 2025

Walkthrough

Adds a new close-on-press-escape feature to the Drawer component, enabling Escape-key-triggered closing. Changes span renderless event handling utilities, Vue component props, and include example components, tests, and API documentation.

Changes

Cohort / File(s) Summary
Core Implementation
packages/renderless/src/drawer/index.ts, packages/renderless/src/drawer/vue.ts, packages/vue/src/drawer/src/pc.vue
Added keyboard event handling for Escape-key closing: new keydown handler and addKeydownEvent/removeKeydownEvent utilities; integrated into renderless API and component lifecycle (mount/unmount); added closeOnPressEscape prop to Vue component.
API Documentation
examples/sites/demos/apis/drawer.js
Registered new close-on-press-escape boolean prop with localized descriptions, PC mode configuration, and stability metadata (v3.28.0).
Demo Components
examples/sites/demos/pc/app/drawer/close-on-press-escape.vue, close-on-press-escape-composition-api.vue
Created two demo components (Options and Composition API) showcasing drawer closing via Escape key.
Demo Documentation & Tests
examples/sites/demos/pc/app/drawer/webdoc/drawer.js, close-on-press-escape.spec.ts
Added demo entry with localized metadata to documentation registry and Playwright E2E test verifying Escape-key-triggered drawer closure.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Keydown handler implementation in packages/renderless/src/drawer/index.ts — verify Escape/Esc key detection and api.handleClose('esc', true) invocation
  • Lifecycle integration in packages/renderless/src/drawer/vue.ts — confirm proper mount/unmount of event listeners and consistency with existing drag-event patterns
  • Event listener cleanup — ensure removeKeydownEvent() correctly detaches document-level keydown listener to prevent memory leaks

Poem

🐰 A key press escapes the drawer's grip,
Escape now closes with a gentle skip,
No more trap when the user wants to flee,
The drawer bows to ESC's decree! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat(vue-renderless/drawer): add close-on-press-escape api' accurately and specifically describes the main change—adding a new close-on-press-escape API to the drawer component across renderless and Vue layers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the enhancement New feature or request (功能增强) label Dec 15, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
examples/sites/demos/pc/app/drawer/webdoc/drawer.js (1)

19-30: Missing English translations.

The en-US values for name and desc are empty. Consider adding translations for internationalization completeness.

       demoId: 'close-on-press-escape',
       name: {
         'zh-CN': '按下 ESC 关闭抽屉',
-        'en-US': ''
+        'en-US': 'Close Drawer on ESC'
       },
       desc: {
         'zh-CN': '<p>添加 <code>close-on-press-escape</code> 属性可以控制是否可以通过 ESC 关闭抽屉。</p>',
-        'en-US': ''
+        'en-US': '<p>Use <code>close-on-press-escape</code> to control whether the drawer can be closed by pressing ESC.</p>'
       },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5bdfec1 and 7c082e1.

📒 Files selected for processing (8)
  • examples/sites/demos/apis/drawer.js (1 hunks)
  • examples/sites/demos/pc/app/drawer/close-on-press-escape-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/drawer/close-on-press-escape.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/drawer/close-on-press-escape.vue (1 hunks)
  • examples/sites/demos/pc/app/drawer/webdoc/drawer.js (1 hunks)
  • packages/renderless/src/drawer/index.ts (1 hunks)
  • packages/renderless/src/drawer/vue.ts (3 hunks)
  • packages/vue/src/drawer/src/pc.vue (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/renderless/src/drawer/index.ts (1)
packages/renderless/src/drawer/vue.ts (1)
  • api (28-28)
packages/renderless/src/drawer/vue.ts (1)
packages/renderless/src/drawer/index.ts (5)
  • keydown (84-98)
  • addKeydownEvent (100-104)
  • removeKeydownEvent (106-110)
  • addDragEvent (173-185)
  • removeDragEvent (187-199)
🔇 Additional comments (8)
packages/renderless/src/drawer/index.ts (2)

83-98: LGTM! Well-structured ESC key handling.

The implementation correctly:

  • Guards with early returns for invisible state and disabled prop
  • Handles both 'Escape' and 'Esc' keys for browser compatibility
  • Forces close with api.handleClose('esc', true) to bypass beforeClose interception

One consideration: if multiple drawers are open, all will respond to the same ESC key. This is typically expected behavior (topmost closes first), but worth noting.


100-111: LGTM!

Clean implementation following the established drag event pattern. Using api.keydown as the handler reference ensures proper cleanup.

examples/sites/demos/pc/app/drawer/close-on-press-escape.spec.ts (1)

1-19: LGTM! Good basic test coverage.

The test correctly validates the ESC-close functionality. Consider adding a complementary test case to verify that a drawer without close-on-press-escape does NOT close on ESC key press, to ensure the prop is properly gated.

packages/vue/src/drawer/src/pc.vue (1)

164-166: LGTM!

Clean prop addition. The renderless layer handles all keydown logic, so no template changes are needed.

examples/sites/demos/pc/app/drawer/close-on-press-escape-composition-api.vue (1)

1-29: LGTM!

Clean composition API demo that correctly demonstrates the close-on-press-escape feature.

examples/sites/demos/pc/app/drawer/close-on-press-escape.vue (1)

1-38: LGTM!

Clean options API demo that correctly demonstrates the close-on-press-escape feature, providing a good counterpart to the composition API version.

packages/renderless/src/drawer/vue.ts (2)

56-60: LGTM!

Clean integration of keydown handling. The methods are correctly wired to use api object references, ensuring proper add/remove pairing for event listeners.


68-80: LGTM!

The keydown listener is added unconditionally with cleanup in onBeforeUnmount. Since the keydown handler itself guards with props.closeOnPressEscape, this approach keeps the lifecycle simple while the guard handles the feature toggle.

Comment on lines +211 to 224
{
name: 'close-on-press-escape',
type: 'boolean',
defaultValue: 'false',
desc: {
'zh-CN': 'ESC 键关闭抽屉',
'en-US': 'ESC key to close drawer'
},
mode: ['pc'],
pcDemo: 'closeOnPressEscape',
meta: {
stable: '3.28.0'
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent pcDemo value format.

The pcDemo value uses camelCase (closeOnPressEscape) while other props use kebab-case matching their demoId (e.g., before-close, mask-closable). This may cause the demo link to not resolve correctly.

-          pcDemo: 'closeOnPressEscape',
+          pcDemo: 'close-on-press-escape',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
name: 'close-on-press-escape',
type: 'boolean',
defaultValue: 'false',
desc: {
'zh-CN': 'ESC 键关闭抽屉',
'en-US': 'ESC key to close drawer'
},
mode: ['pc'],
pcDemo: 'closeOnPressEscape',
meta: {
stable: '3.28.0'
}
}
{
name: 'close-on-press-escape',
type: 'boolean',
defaultValue: 'false',
desc: {
'zh-CN': 'ESC 键关闭抽屉',
'en-US': 'ESC key to close drawer'
},
mode: ['pc'],
pcDemo: 'close-on-press-escape',
meta: {
stable: '3.28.0'
}
}
🤖 Prompt for AI Agents
In examples/sites/demos/apis/drawer.js around lines 211 to 224, the pcDemo value
uses camelCase ("closeOnPressEscape") while the rest use kebab-case matching
demoIds; update the pcDemo string to the kebab-case demo id
("close-on-press-escape") so the demo link resolves consistently with other
props.

@zzcr zzcr merged commit e207024 into opentiny:dev Dec 16, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request (功能增强)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants