Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

🐛 [UI/Fidelity] 'Combobox' + 'isExpanded:false' causes longest option to be displayed in two lines #382

Closed
henry2man opened this issue Jun 1, 2022 · 6 comments · Fixed by #481
Labels
enhancement New feature or request

Comments

@henry2man
Copy link
Contributor

Describe the bug
Using Combobox with isExpanded: false causes longest option in dropdown to show in two lines. Maybe this is a padding problem/sizing problem?

To Reproduce

Combobox(
              isExpanded: false,
              onChanged: (option) => print("Option selected: option"),
              items: ["Windows", "MacOS", "Linux", "Web", "Android", "iOS"]
                  .map((e) => ComboboxItem(value: e, child: Text(e)))
                  .toList(),
              value: "Windows",
            )

Expected behavior
The list of options in the dropdown shows in one line

Screenshots
Captura de Pantalla 2022-06-01 a las 10 23 42
Captura de Pantalla 2022-06-01 a las 17 37 12

Additional context
Add any other context about the problem here.

@henry2man henry2man changed the title 🐛 [UI/Fidelity] Combobox not expanded, longest option displays in two lines 🐛 [UI/Fidelity] Combobox + isExpanded:false causes longest option displays in two lines Jun 1, 2022
@henry2man henry2man changed the title 🐛 [UI/Fidelity] Combobox + isExpanded:false causes longest option displays in two lines 🐛 [UI/Fidelity] 'Combobox' + 'isExpanded:false' causes longest option displays in two lines Jun 1, 2022
@bdlukaa bdlukaa added the bug Something isn't working label Jun 1, 2022
@henry2man
Copy link
Contributor Author

henry2man commented Jun 1, 2022

Changing this the issue is gone... but I'm not sure why we have here a constant value of 12px for the padding (maybe this comes from specification, I don't know):

Captura de Pantalla 2022-06-01 a las 17 58 38

Also the dropdown animation is nice because Text is placed in the same position.

diff --git a/lib/src/controls/form/combo_box.dart b/lib/src/controls/form/combo_box.dart
--- a/lib/src/controls/form/combo_box.dart	(revision 34980480d486530acbfe21f3f3954ab111c67e00)
+++ b/lib/src/controls/form/combo_box.dart	(date 1654098939196)
@@ -11,7 +11,7 @@
 
 const Duration _kComboboxMenuDuration = Duration(milliseconds: 300);
 const double _kMenuItemHeight = kPickerHeight;
-const EdgeInsets _kMenuItemPadding = EdgeInsets.symmetric(horizontal: 12.0);
+const EdgeInsets _kMenuItemPadding = EdgeInsets.symmetric(horizontal: 6.0);
 const EdgeInsetsGeometry _kAlignedButtonPadding = EdgeInsets.only(
   top: 4.0,
   bottom: 4.0,

@bdlukaa
Copy link
Owner

bdlukaa commented Jun 21, 2022

You can customize the Combobox width by wrapping it in a SizedBox and defining a width. The popup will take the width of the Combobox button. Can you try wrapping your Combobox in a SizedBox?

SizedBox(
  width: 150.0,
  child: Combobox(...),
),

@henry2man
Copy link
Contributor Author

I did this as a workaround but key thing here is to have dinamically sized widgets isExpanded: false depending of Combobox items

@bdlukaa
Copy link
Owner

bdlukaa commented Jun 29, 2022

depending of Combobox items

The Combobox popup needs to have the same width as the combobox button, which means the content WILL overflow if the button is too short but the content is too long. The dev can set the combobox width, as well as placeholder content that will size the button correctly.

Closing this as invalid

@bdlukaa bdlukaa closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2022
@bdlukaa bdlukaa added invalid This doesn't seem right and removed bug Something isn't working labels Jun 29, 2022
@henry2man
Copy link
Contributor Author

The Combobox popup needs to have the same width as the combobox button

The popup will be size according Combobox size, but if you open a Combobox the size of the popup is a little bit bigger (check the demo bellow). So I don't know why can't we add some extra size to the popup (and/or adjusting the padding, as I proposed) in order to solve this issue.

The dev can set the combobox width, as well as placeholder content that will size the button correctly

You indicate that the developer can set the width, but precisely what we want to do here is NOT to have to define this width, but rather that the width depends on the contents of the Combobox.

In other words, if you use isExpanded: false, how do you make it so that the contents don't look bad when the Combobox is opened? I don't see the way without having to hide and/or force the size of the items, but that's exactly what I don't want to do with this configuration.

Here it is a little demo comparing the equivalent component in Material (Dropdown) that do not have this behavior, displaying the same list of items successfully, regardless of every item content length:

Grabacion.de.pantalla.2022-06-30.a.las.8.11.36.mov
import 'dart:math';

import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart' as mat;

void main() {
  runApp(ComboboxBugDemo());
}

class ComboboxBugDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FluentApp(routes: {"/": (context) => Main()});
  }
}

class Main extends StatelessWidget {
  const Main({
    Key? key,
  }) : super(key: key);

  static const chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];

  @override
  Widget build(BuildContext context) {
    // generates a new Random object
    final _random = new Random();

    String? longestOption = null;
    List<String> items = [];
    for (int i = 0; i < 10; i++) {
      int wordsize = _random.nextInt(30);
      String word = "";
      for (int j = 0; j < wordsize; j++) {
        word += chars[_random.nextInt(chars.length)];
      }
      items.add(word);
      if (longestOption == null || longestOption.length < word.length) {
        longestOption = word;
      }
    }

    return NavigationView(
      appBar: NavigationAppBar(title: Text("FluentUI 382 demo")),
      content: Column(
        children: [
          Row(
            children: [
              Text("FluentUI + isExpanded: false"),
              Combobox<String>(
                  isExpanded: false,
                  onChanged: (e) {},
                  value: longestOption,
                  items: items
                      .map((e) => ComboboxItem<String>(
                            child: Text(e),
                            value: e,
                          ))
                      .toList())
            ],
          ),
          mat.Material(
            child: Row(
              children: [
                Text("Material + isExpanded: false"),
                mat.DropdownButton<String>(
                    isExpanded: false,
                    onChanged: (e) {},
                    value: longestOption,
                    items: items
                        .map((e) => mat.DropdownMenuItem<String>(
                              child: Text(e),
                              value: e,
                            ))
                        .toList())
              ],
            ),
          ),
        ],
      ),
    );
  }
}

@bdlukaa bdlukaa reopened this Jun 30, 2022
@bdlukaa bdlukaa added enhancement New feature or request and removed invalid This doesn't seem right labels Jun 30, 2022
@henry2man henry2man changed the title 🐛 [UI/Fidelity] 'Combobox' + 'isExpanded:false' causes longest option displays in two lines 🐛 [UI/Fidelity] 'Combobox' + 'isExpanded:false' causes longest option to be displayed in two lines Jun 30, 2022
@bdlukaa bdlukaa linked a pull request Aug 20, 2022 that will close this issue
3 tasks
bdlukaa added a commit that referenced this issue Aug 21, 2022
- `ComboBox` updates:
  - **BREAKING** Renamed `Combobox` to `ComboBox`
  - Implement `EditableComboBox`, a combo box that accepts items that aren't listed ([#244](#244)) 
  - `ComboBox.isExpanded: false` now correctly sets the button width ([#382](#382))
  - `ComboBox`'s items height are correctly calculated, as well as initial scroll offset ([#472](#478))
  - **BREAKING** `ComboBox.disabledHint` was renamed to `ComboBox.disabledPlaceholder`
  - Added `ComboBoxFormField` and `EditableComboBoxFormField` ([#373](#373))
@henry2man
Copy link
Contributor Author

henry2man commented Sep 2, 2022

@bdlukaa Confirmed as fixed. Thanks!!

Captura de Pantalla 2022-09-03 a las 8 48 49

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants