Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(useFocusTrap): expose updateContainerElements for dynamic contai…#4849

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
PeikyLiu wants to merge4 commits intovueuse:main
base:main
Choose a base branch
Loading
fromPeikyLiu:useFocusTrap/updateContainerElements

Conversation

PeikyLiu
Copy link

@PeikyLiuPeikyLiu commentedJun 30, 2025
edited by ilyaliao
Loading

🚀 Feature: Expose updateContainerElements method in useFocusTrap

Description

This PR exposes theupdateContainerElements method from the underlying focus-trap library, allowing users to dynamically update focus trap containers while the trap is active.

Related Issues

resolve#4848

📋 Changes

  • AddedupdateContainerElements method toUseFocusTrapReturn interface
  • CreatedContainerElements type alias usingParameters<FocusTrap['updateContainerElements']>[0]
  • Updated return type to handleundefined case when trap is not initialized
  • Added basic container switching demo in demo.vue

🔧 Technical Details

  • Uses TypeScript'sParameters utility type to automatically inherit parameter types from focus-trap library
  • Ensures type consistency with the underlying focus-trap library

📚 Example Usage

const{ updateContainerElements, activate}=useFocusTrap(target)activate()updateContainerElements(target2.value)// Switch to different container

🔄 Breaking Changes

None - this is a purely additive change.

@dosubotdosubotbot added size:MThis PR changes 30-99 lines, ignoring generated files. enhancementNew feature or request labelsJun 30, 2025
ilyaliao
ilyaliao previously approved these changesJul 4, 2025
@dosubotdosubotbot added the lgtmThis PR has been approved by a maintainer labelJul 4, 2025
Comment on lines 98 to 103
const updateContainerElements = (el: ContainerElements) => {
if (trap) {
trap.updateContainerElements(el)
return trap
}
}
Copy link
Collaborator

@OrbisKOrbisKJul 6, 2025
edited
Loading

Choose a reason for hiding this comment

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

I think we dont want to expose this, but watch the target andupdateContaienrElements when target changes (instead of activate/deactivate)? wdyt@ilyaliao

Copy link
Member

@ilyaliaoilyaliaoJul 8, 2025
edited
Loading

Choose a reason for hiding this comment

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

I think we dont want to expose this, but watch the target andupdateContaienrElements when target changes (instead of activate/deactivate)? wdyt@ilyaliao

Yes, that's what I initially had in mind as well. We could initialize once withcreateFocusTrap, and then update the element viaupdateContainerElements afterwards. But I haven’t looked into the feasibility of this approach in depth yet.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@PeikyLiu wdyt?

Copy link
Author

Choose a reason for hiding this comment

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

ok,I'll try based your idea,but it will be take some time

ilyaliao and OrbisK reacted with heart emoji
Copy link
Author

Choose a reason for hiding this comment

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

I think we dont want to expose this, but watch the target andupdateContaienrElements when target changes (instead of activate/deactivate)? wdyt@ilyaliao

To summarize: you suggest using watch to monitor target changes inside the hook, while keeping the activate/deactivate methods exposed, right?

ilyaliao reacted with thumbs up emoji
Copy link
Collaborator

Choose a reason for hiding this comment

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

we always want to use the target thats passed to the composable. If we want to change the target we want to update the target ref. So we can use updateContainerElements, we should do this while watching target 😄

ilyaliao reacted with thumbs up emoji
@dosubotdosubotbot added size:LThis PR changes 100-499 lines, ignoring generated files. and removed size:MThis PR changes 30-99 lines, ignoring generated files. labelsJul 18, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@OrbisKOrbisKOrbisK left review comments

@ilyaliaoilyaliaoilyaliao left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
enhancementNew feature or requestlgtmThis PR has been approved by a maintainersize:LThis PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

useFocusTrap | ImplementupdateContainerElements()
3 participants
@PeikyLiu@OrbisK@ilyaliao

[8]ページ先頭

©2009-2025 Movatter.jp