Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Input box for ui-select multiple ALWAYS forcing text entry at new line #1980

Open
aronmgv opened this issue Apr 21, 2017 · 21 comments · May be fixed by #2016
Open

Input box for ui-select multiple ALWAYS forcing text entry at new line #1980

aronmgv opened this issue Apr 21, 2017 · 21 comments · May be fixed by #2016

Comments

@aronmgv
Copy link

aronmgv commented Apr 21, 2017

Bug description:

Input box for ui-select multiple forcing text entry at new line, even if values do not take up entire first line

There is already closed issue for this #1556 undesired behavior.. but for older version. Since I got no help there, opening new issue.

Link to minimally-working plunker that reproduces the issue:

plunker
All selects forces new line when there is at least 1 item selected.. this was not happening before..

Notice also that only like 40% of the line is clickable in order to start typing in it:
image

Version of Angular, UI-Select, and Bootstrap/Select2/Selectize CSS

Angular: 1.6.4
UI-Select: ^0.19.8
Bootstrap/Select2/Selectize CSS (if applicable): ^3.3.7

@Jefiozie
Copy link
Contributor

Hi,

Thanks for the issue, maybe you could have a look where the problem is coming from and make a PR?
Happy to review for you.

@frame
Copy link

frame commented Apr 24, 2017

I didn't find the actual cause yet, but it got introduced in 0.19.7. Reverting back to 0.19.5 fixes the issue.

Update: I believe I found the culprit: 7ad4ef1

@fosron
Copy link

fosron commented Apr 25, 2017

+1

@aurelienlt
Copy link

Oh I haven't seen it was a recent issue, I commented the older one. Here is the fix I found.

In the code of the updateIfVisible function, it tries to make the input fit in the line using var inputWidth = containerWidth - input.offsetLeft.

updateIfVisible = function(containerWidth) {
  if (containerWidth === 0) {
    return false;
  }
  var inputWidth = containerWidth - input.offsetLeft;
  if (inputWidth < 50) inputWidth = containerWidth;
  ctrl.searchInput.css('width', inputWidth+'px');
  return true;
}

However it cannot be done since the input is already on the second line. By reducing the input first and enlarging it to the rest of the block, it works:

updateIfVisible = function(containerWidth) {
  if (containerWidth === 0) {
    return false;
  }
  ctrl.searchInput.css('width', '50px');
  setTimeout(function(){
    var inputWidth = Math.max(50, containerWidth - input.offsetLeft - 10);
    ctrl.searchInput.css('width', inputWidth+'px');
  }, 0);
  return true;
}

@mkeremguc
Copy link

mkeremguc commented May 5, 2017

also, there is a height problem for multiple. the input's height is shorter when it is empty, at least for bootstrap theme. you can compare multiple input's height with non-multiple

@giacomomasseron
Copy link

+1, same problem with chrome

@AbdallaElabd
Copy link

Changing this line https://github.com/angular-ui/ui-select/blob/master/dist/select.js#L839
from
var inputWidth = containerWidth - input.offsetLeft;
into
var inputWidth = containerWidth - angular.element(input).offset().left;
fixes it for me.

@ciaran-phillips
Copy link

ciaran-phillips commented May 18, 2017

As far as I can tell the root issue is that ui-select is relying on the element's clientWidth property when calculating the available area for the input. clientWidth includes the element's padding, so it overestimates the available area.

Previously, ui-select compensated by subtracting an extra 10px from the container width:

var inputWidth = containerWidth - input.offsetLeft - 10;

But that was removed in 7ad4ef1

Even if that was change was undone, I believe it would still break for anyone who wanted to set a larger custom padding on their element. I think the best solution is probably to take into account the actual computed padding values from window.getComputedStyle(element) when determining available area

aurelienlt pushed a commit to aurelienlt/ui-select that referenced this issue Jun 3, 2017
DmitryGonchar added a commit to DmitryGonchar/ui-select that referenced this issue Jun 17, 2017
input is not too big or too small - it takes the whole remaining part of the current row.
If smaller than the min input width - goes to the next row

closes angular-ui#1980, possibly angular-ui#2010
DmitryGonchar added a commit to DmitryGonchar/ui-select that referenced this issue Jun 17, 2017
input is not too big or too small - it takes the whole remaining part of the current row.
If smaller than the min input width - goes to the next row

closes angular-ui#1980, possibly angular-ui#2010
@aurelienlt
Copy link

Finally got a clue why the "-10" was removed. In not multiple case, this -10 will shrink from 10 pixels the input (so visually, the whole select shrinks from 10 pixels).

I'm now using:

var inputWidth = containerWidth - input.offsetLeft - (ctrl.multiple ? 10 : 0);

@sonmezonur
Copy link

None of solutions actually fix the problem. I think the problem is much deeper since it does not provide enough flexibility. User should be able to access drop-down list by clicking ANY space on input box. If you decrease the input width as suggested, generally ends up with less interaction area even if it may not force text entry in new line.

simon-n pushed a commit to simon-n/ui-select that referenced this issue Aug 22, 2017
…tiple" control (missing a valid sourcemap because of wrecked build environment)
simon-n pushed a commit to simon-n/ui-select that referenced this issue Aug 22, 2017
…dth for "multiple" control (missing a valid sourcemap because of wrecked build environment)
zollinger pushed a commit to zollinger/ui-select that referenced this issue Aug 22, 2017
- Account for paddings on input container in case box-sizing: border-box
is set.
- Added some tests for this case

Closes angular-ui#1980.
zollinger pushed a commit to zollinger/ui-select that referenced this issue Aug 22, 2017
- Account for paddings on input container in case box-sizing: border-box
is set.
- Added some tests for this case

Closes angular-ui#1980.
zollinger pushed a commit to zollinger/ui-select that referenced this issue Aug 23, 2017
- Account for paddings on input container in case box-sizing: border-box
is set.
- Added some tests for this case

Closes angular-ui#1980.
zollinger pushed a commit to zollinger/ui-select that referenced this issue Aug 24, 2017
- Account for paddings on input container in case box-sizing: border-box
is set.
- Added some tests for this case

Closes angular-ui#1980.
@stephen-dahl
Copy link

stephen-dahl commented Aug 31, 2017

I don't know what the browser support requirements are but this is an easy fix for flexbox (IE10+) the current structure for multi-select is (not exact names)

<div class="wrapper">
    <span>
        <span>first selection</span>
        ....
    </span>
    <input class="ui-select-search">
</wrapper div>

change it to

<div class="wrapper">
    <span>first selection</span>
    ....
    <input class="ui-select-search">
</wrapper div>

and give it the following css

.wrapper{
    display: flex;
    flex-wrap: wrap;
}
.ui-select-search{
    flex-grow: 1;
}

this will allow you to let css handle it automagically and not have js setting the width at all

I also agree with the statement above that clicking anywhere in the box should open the dropdown and focus the input

@andreiho
Copy link

andreiho commented Sep 12, 2017

I would also expect to be able to click anywhere in the box to search.

We can achieve this easily with basic HTML, without any complicated calculations. Just wrap ui-select-match and ui-select-search in a <label>:

<label>
  <span class="ui-select-match">
    ...
  </span>

  <input type="text" class="ui-select-search">
</label>

And add the following CSS to make it look like the whole thing is an input:

label {
  display: block;
  cursor: text;
}

PR: #2057

@parker789
Copy link

parker789 commented Nov 27, 2017

Can we get a fix for this merged? This really breaks the functionality of this library.

edit: I personally think that a combination of @andreiho and @abdallamohamed solutions should be merged.

mkresse pushed a commit to espresto/ui-select that referenced this issue Dec 4, 2017
@jfinckh
Copy link

jfinckh commented Jan 15, 2018

Any Update on this?

@parker789
Copy link

I've come to the conclusion that this library is dead. Was good.. but now I feel that moving away is the best call for production level apps

@ChristianGruen
Copy link

If this library should be dead indeed, couldanyone recommend good alternatives?

@andreiho
Copy link

@ChristianGruen There aren't any good alternatives that can do everything this project can do. There are some simpler ones for doing tagging, such as angular-chips or ngTagsInput, but as you can see most of these projects aren't that active either.

@Pritraj
Copy link

Pritraj commented Aug 8, 2018

yes #2125 is working for my case thanks @sunilkandakatla

@stephen-dahl
Copy link

Can this be closed? it has a merged pr and is very old.

@svpace
Copy link

svpace commented Aug 17, 2018 via email

@frame
Copy link

frame commented Aug 23, 2018

@stephen-dahl I just successfully tested PR #2125 on Chrome 68, Firefox 61 and IE 11 and it does fix the problem in my projects, but the PR hasn't been merged into master yet.

msiemczyk pushed a commit to msiemczyk/ui-select that referenced this issue Oct 20, 2023
input is not too big or too small - it takes the whole remaining part of the current row.
If smaller than the min input width - goes to the next row

closes angular-ui#1980, possibly angular-ui#2010

(cherry picked from commit 2fbd285)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.