Skip to content

Items in the overflow of the TextSelectionToolbar should take the width of the largest item #144089

Closed

Description

@JannikWinter

Steps to reproduce

  1. create a Material style TextSelectionToolbar with contextMenuBuilder of a TextField, TextFormField or similar
  2. make the context menu items overflow to show the overflow button
    2.1. if you are in DartPad and the menu does not overflow, you can drag the vertical divider between the code and the display to make the display smaller.
    2.2. similarly, you can add more ContextMenuButtonItems to the Toolbar to make it wider
  3. open the overflow menu

Expected results

All items in the overflow menu should have the width of the largest item

Actual results

All items have their own minimal width resulting in a non-clickable area beside them

Code sample

Code sample
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();

    if (kIsWeb) {
      BrowserContextMenu.disableContextMenu();
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: TextFormField(
            initialValue: "Example Text",
            contextMenuBuilder: (context, editableTextState) {
              final anchors = editableTextState.contextMenuAnchors;
              final buttonItems = [
                ContextMenuButtonItem(label: "More items", onPressed: () {}),
                ContextMenuButtonItem(label: "To make the menu", onPressed: () {}),
                ContextMenuButtonItem(label: "Overflow", onPressed: () {}),
                ...editableTextState.contextMenuButtonItems,
                ContextMenuButtonItem(label: "Long example menu item", onPressed: () {}),
                ContextMenuButtonItem(label: "Short", onPressed: () {}),
              ];

              // Follwing is the code that AdaptiveTextSelectionToolbar uses when the platform is android.
              // I copied it to force the material style toolbar

              final List<Widget> buttons = <Widget>[];
              for (int i = 0; i < buttonItems.length; i++) {
                final ContextMenuButtonItem buttonItem = buttonItems[i];
                buttons.add(TextSelectionToolbarTextButton(
                  padding: TextSelectionToolbarTextButton.getPadding(
                      i, buttonItems.length),
                  onPressed: buttonItem.onPressed,
                  child: Text(AdaptiveTextSelectionToolbar.getButtonLabel(
                      context, buttonItem)),
                ));
              }

              return TextSelectionToolbar(
                anchorAbove: anchors.primaryAnchor,
                anchorBelow: anchors.secondaryAnchor == null
                    ? anchors.primaryAnchor
                    : anchors.secondaryAnchor!,
                children: buttons,
              );
            },
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

grafik
The buttons with shorter text do not take the full width, resulting in a non-clickable area on their right hand side

Logs

No response

Flutter Doctor output

Doctor output none

The example code was executed in DartPad with Dart 3.3.0 and Flutter 3.19.0 on the Stable channel

Activity

  1. changed the title [-]Items in the overflow the TextSelectionToolbar should take the width of the largest item[/-] [+]Items in the overflow of the TextSelectionToolbar should take the width of the largest item[/+] on Feb 24, 2024
  2. dam-ease commented on Feb 26, 2024

    @dam-ease

    Thanks for filing this @JannikWinter.
    I can't seem to reproduce this on my end both on mobile and testing with DartPad (the toolbar doesn't come up).

    Screenshot 2024-02-26 at 09 36 55

    Can you please provide more information on the reproduction steps?

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 26, 2024
  4. JannikWinter commented on Feb 26, 2024

    @JannikWinter
    Author

    Thank you for looking into this and sorry for the inconvenience @dam-ease.

    I updated the reproduction steps and the example code :)

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 26, 2024
  6. dam-ease commented on Feb 27, 2024

    @dam-ease

    Thanks for your response and the update @JannikWinter
    I can reproduce this on the latest master and stable channels.

    Simulator.Screen.Recording.-.iPhone.15.-.2024-02-27.at.07.43.29.mp4
    stable, master flutter doctor -v

    [!] Flutter (Channel stable, 3.19.1, on macOS 14.2.1 23C71 darwin-arm64, locale
        en-NG)
        • Flutter version 3.19.1 on channel stable at
          /Users/damilolaalimi/sdks/flutter
        ! Warning: `dart` on your path resolves to
          /opt/homebrew/Cellar/dart/3.1.5/libexec/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/damilolaalimi/sdks/flutter.
          Consider adding /Users/damilolaalimi/sdks/flutter/bin to the front of your
          path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision abb292a07e (6 days ago), 2024-02-20 14:35:05 -0800
        • Engine revision 04817c99c9
        • Dart version 3.3.0
        • DevTools version 2.31.1
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android
          Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build
          17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.2)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 15C500b
        • CocoaPods version 1.14.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build
          17.0.6+0-17.0.6b802.4-9586694)
    
    [!] Android Studio (version unknown)
        • Android Studio at /Users/damilolaalimi/Downloads/Android Studio
          Preview.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        ✗ Unable to determine Android Studio version.
        • Java version OpenJDK Runtime Environment (build
          17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] VS Code (version 1.86.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.78.0
    
    [✓] VS Code (version 1.83.1)
        • VS Code at /Users/damilolaalimi/Downloads/Visual Studio Code.app/Contents
        • Flutter extension version 3.78.0
    
    [✓] Connected device (5 available)
        • sdk gphone64 arm64 (mobile) • emulator-5554                        •
          android-arm64  • Android 14 (API 34) (emulator)
        • Damilola’s iPhone (mobile)  • 00008110-001964480AE1801E            • ios
          • iOS 17.1.1 21B91
        • iPhone 15 (mobile)          • DBCC5388-DA57-470E-8F0E-477EA0AA3C3A • ios
          • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
        • macOS (desktop)             • macos                                •
          darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
        • Chrome (web)                • chrome                               •
          web-javascript • Google Chrome 122.0.6261.69
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
    
    [!] Flutter (Channel master, 3.20.0-13.0.pre.47, on macOS 14.2.1 23C71 darwin-arm64, locale en-NG)
        • Flutter version 3.20.0-13.0.pre.47 on channel master at /Users/damilolaalimi/fvm/versions/master
        ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.1.5/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/damilolaalimi/fvm/versions/master. Consider adding /Users/damilolaalimi/fvm/versions/master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 331769f397 (3 hours ago), 2024-02-26 23:50:40 -0500
        • Engine revision 0bc21ea7bc
        • Dart version 3.4.0 (build 3.4.0-179.0.dev)
        • DevTools version 2.33.0-dev.11
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.2)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 15C500b
        • CocoaPods version 1.14.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    
    [!] Android Studio (version unknown)
        • Android Studio at /Users/damilolaalimi/Downloads/Android Studio Preview.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        ✗ Unable to determine Android Studio version.
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] VS Code (version 1.86.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.78.0
    
    [✓] VS Code (version 1.83.1)
        • VS Code at /Users/damilolaalimi/Downloads/Visual Studio Code.app/Contents
        • Flutter extension version 3.78.0
    
    [✓] Connected device (6 available)
        • sdk gphone64 arm64 (mobile)     • emulator-5554                        • android-arm64  • Android 14 (API 34) (emulator)
        • Damilola’s iPhone (mobile)      • 00008110-001964480AE1801E            • ios            • iOS 17.1.1 21B91
        • iPhone 15 (mobile)              • DBCC5388-DA57-470E-8F0E-477EA0AA3C3A • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
        • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
        • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 14.2.1 23C71 darwin-arm64
        • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 122.0.6261.69
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
    

  7. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-designOwned by Design Languages team
    f: selectionSelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs
    and removed
    in triagePresently being triaged by the triage team
    on Feb 27, 2024
  8. self-assigned this
    on Feb 28, 2024
  9. added
    P2Important issues not at the top of the work list
    triaged-designTriaged by Design Languages team
    on Feb 28, 2024
  10. moved this from To do to In progress in Nevercodeon Feb 29, 2024
  11. moved this from In progress to PR submitted in Nevercodeon Feb 29, 2024
  12. moved this from PR submitted to Done (PR merged) in Nevercodeon Mar 1, 2024
  13. added
    r: fixedIssue is closed as already fixed in a newer version
    on Mar 1, 2024
  14. github-actions commented on Mar 15, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  15. locked as resolved and limited conversation to collaborators on Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: selectionSelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIsfound in release: 3.19Found to occur in 3.19found in release: 3.20Found to occur in 3.20frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

  • Status
    Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions