Skip to content

feat: add descendantsAreTraversable parameter to useFocusNode #476

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

Merged
merged 1 commit into from
Aug 12, 2025

Conversation

gabber235
Copy link
Contributor

@gabber235 gabber235 commented Aug 6, 2025

Summary

Adds support for the descendantsAreTraversable parameter to useFocusNode hook to match Flutter's FocusNode constructor.

Context

Flutter added the descendantsAreTraversable parameter to FocusNode to control whether descendants of this focus node can be traversed by the focus system. This parameter was missing from the useFocusNode hook, preventing users from accessing this functionality through flutter_hooks.

Changes

  • Added descendantsAreTraversable parameter to useFocusNode function with default value true
  • Updated _FocusNodeHook class to handle the new parameter
  • Modified _FocusNodeHookState to properly initialize and update the parameter
  • Added updated tests for the new parameter

Testing

  • All existing tests continue to pass (218 tests total)
  • Update tests to verify default value matches Flutter's FocusNode
  • Update tests to verify parameter is properly passed to FocusNode constructor
  • Update tests to verify parameter updates work correctly when hook rebuilds
  • Code passes all linting rules

Backward Compatibility

Fully backward compatible - existing code will continue to work unchanged as the new parameter has a default value of true matching Flutter's behavior.

References

Summary by CodeRabbit

  • New Features
    • Added support for configuring the traversability of descendants in the focus node hook with a new parameter.
  • Tests
    • Updated tests to verify correct handling of the new descendants traversability option.

Copy link

coderabbitai bot commented Aug 6, 2025

Walkthrough

A new boolean parameter, descendantsAreTraversable, was added to the useFocusNode hook in the Flutter Hooks package. This parameter is now configurable, propagated through the hook's internal classes, and passed to the underlying FocusNode. Corresponding tests were updated to verify correct handling and propagation of this property.

Changes

Cohort / File(s) Change Summary
Hook Implementation Update
packages/flutter_hooks/lib/src/focus_node.dart
Added descendantsAreTraversable parameter to useFocusNode and internal hook classes; updated initialization and state management to support the new property.
Test Enhancements
packages/flutter_hooks/test/use_focus_node_test.dart
Updated tests to check descendantsAreTraversable handling, including default, parameterized, and changed values.

Sequence Diagram(s)

sequenceDiagram
    participant Widget
    participant useFocusNode
    participant _FocusNodeHook
    participant FocusNode

    Widget->>useFocusNode: Call with descendantsAreTraversable
    useFocusNode->>_FocusNodeHook: Pass descendantsAreTraversable
    _FocusNodeHook->>FocusNode: Construct with descendantsAreTraversable
    Note right of FocusNode: descendantsAreTraversable set
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

A hop, a skip, a focus node anew,
With traversable descendants, now in view!
Tests updated, checks in place,
Ensuring widgets keep their pace.
The hook grows stronger, swift and true—
Another leap for Flutter’s crew!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e802dd3 and 9fd4957.

📒 Files selected for processing (2)
  • packages/flutter_hooks/lib/src/focus_node.dart (5 hunks)
  • packages/flutter_hooks/test/use_focus_node_test.dart (5 hunks)
🔇 Additional comments (8)
packages/flutter_hooks/lib/src/focus_node.dart (5)

13-13: LGTM! Parameter addition maintains backward compatibility.

The descendantsAreTraversable parameter is correctly added with a default value of true, which preserves existing behavior and maintains backward compatibility.


22-22: Correct parameter propagation to hook constructor.

The parameter is properly passed to the _FocusNodeHook constructor, maintaining consistency with the function signature.


34-34: Proper hook implementation pattern followed.

The parameter is correctly declared as required in the constructor and stored as a final field, following the established pattern for other boolean parameters in the hook.

Also applies to: 42-42


57-57: Parameter correctly passed to FocusNode constructor.

The descendantsAreTraversable parameter is properly passed to the underlying FocusNode during initialization.


67-67: Parameter update handled correctly in didUpdateHook.

The parameter is properly updated when the hook's configuration changes, ensuring the FocusNode stays in sync with the hook's parameters.

packages/flutter_hooks/test/use_focus_node_test.dart (3)

79-80: Good test coverage for default value behavior.

The test correctly verifies that the hook's default value for descendantsAreTraversable matches Flutter's FocusNode default, ensuring consistency.


96-96: Proper parameterized testing.

The test correctly verifies that the descendantsAreTraversable parameter can be explicitly set to false and that the FocusNode reflects this value.

Also applies to: 107-107


125-125: Comprehensive parameter change testing.

The test properly verifies that the parameter can be changed during hook updates, including the scenario where it defaults back to true when not explicitly specified. This ensures the hook correctly handles parameter lifecycle.

Also applies to: 148-148

✨ Finishing Touches
🧪 Generate unit tests
  • 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rrousselGit
Copy link
Owner

LGTM thanks!

@rrousselGit rrousselGit merged commit 571826a into rrousselGit:master Aug 12, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants