Add TextFieldMenuItem feature with editable text fields in menu dropdown #226
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add TextFieldMenuItem: Editable text fields in menu bar dropdowns
Overview
This PR adds a new
TextFieldMenuItemclass that allows editable text fields to appear directly inside menu bar dropdowns, following the same pattern as the existingSliderMenuItem.Motivation
Menu bar apps often need to collect simple text input from users (searches, API keys, usernames, etc.). Currently, this requires opening separate windows or alerts. With
TextFieldMenuItem, users can type directly into the menu, providing a more streamlined and native macOS experience.Features
NSTextFieldfor native look and feel@text_fielddecorator for declarative menu creationUsage
Direct instantiation:
Using the decorator:
Implementation Details
SliderMenuItemfor consistencyNSViewcontainer withNSTextFieldchildNSApp._ns_to_py_and_callbackNSTextFieldRoundedBezelstyle for modern appearanceAPI
TextFieldMenuItem
Parameters:
value(str): Initial text value (default: '')placeholder(str): Placeholder text (default: '')callback(callable): Function called on text change (default: None)dimensions(tuple): Width and height in pixels (default: (200, 24))margins(tuple): Left, top, right, bottom margins (default: (15, 5, 15, 5))Properties:
value- Get/set current textplaceholder- Get/set placeholder textcallback- Get current callback functionMethods:
set_callback(callback)- Set or change callback functionFiles Changed
TextFieldMenuItemclass andtext_fielddecoratorTesting
Tested on macOS with PyObjC. The feature integrates seamlessly with existing rumps apps and follows the same patterns as other menu item types.
Backwards Compatibility
This is a purely additive change with no breaking modifications to existing functionality.