ui-select icon indicating copy to clipboard operation
ui-select copied to clipboard

Width of the select when an item with large name is selected (question)

Open germanger opened this issue 10 years ago • 22 comments
trafficstars

This is my ui-select:

<ui-select ng-model="selectedReceiver.selected" ng-disabled="fetchingReceivers || receivers.length == 0">
    <ui-select-match placeholder="">{{$select.selected.code}} - {{$select.selected.name}}</ui-select-match>
    <ui-select-choices repeat="receiver in receivers | filterBy: ['name', 'code']: $select.search"> 
        <div ng-bind-html="receiver.name | highlight: $select.search"></div>
        <small>Code: <span ng-bind-html="receiver.code | highlight: $select.search"></span></small>
        <hr style="margin-top: 0px; margin-bottom: 0px; border-top: 1px solid #C0C0C0;"/>
    </ui-select-choices>
</ui-select>

When an item is selected, say:

     {
           code: "some large code",
           name: "some very large name, foo bar qux"
     }

the ui-select-match shows "some large code - some very large name, foo bar qux" (as expected), but this is so large that resizes the control (the <button> in which the directive is translated).

visual example

Question: Is there a setting for preventing this resize?

germanger avatar May 17 '15 19:05 germanger

Perhaps the use of text-overflow: ellipsis; could be of some use for a fix. https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow

blowsie avatar Jun 03 '15 12:06 blowsie

Its worth looking at the clear selection button in this as well, It also has layout issues.

image

blowsie avatar Jun 08 '15 11:06 blowsie

After just a few lines of css; image

.ui-select-match-text{
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 40px;
}
.ui-select-toggle > .btn.btn-link {
  margin-right: 10px;
  top: 6px;
  position: absolute;
  right: 10px;
}

blowsie avatar Jun 08 '15 11:06 blowsie

Referencing https://github.com/angular-ui/ui-select/issues/975

blowsie avatar Jun 08 '15 11:06 blowsie

hummm is not working for me.

Are those css definitions in a new css file after the ui-select css file? thats what I tried. Or are you overriding ui-select css file itself?

germanger avatar Jun 08 '15 16:06 germanger

The following just worked for me.

.ui-select-match-text > span {
    width: 80%;
    overflow: hidden;
    text-overflow: ellipsis;
    position: absolute;
}

I'm not touching original ui-select css file. This definitions are set after that. As you can see I'm targeting to the span that is inside .ui-select-match-text

germanger avatar Jun 08 '15 16:06 germanger

Perhaps we have a different version, but using width:80% is not a good idea. you should opt for padding , or similar instead

blowsie avatar Jun 09 '15 07:06 blowsie

I am having the same issue.

firstdev avatar Jun 12 '15 06:06 firstdev

This is needed for the ui-select-placeholder as well. I have:

.ui-select-placeholder, .ui-select-match-text {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 40px;
}

rzschech avatar Jun 29 '15 17:06 rzschech

@germanger solution worked for me. thanks.

uguryilmaz avatar Oct 01 '15 08:10 uguryilmaz

This is probably best added to the library itself - PRs welcome.

wesleycho avatar Mar 27 '16 22:03 wesleycho

How to fix this when using multipleoption?

Hesesses avatar Oct 19 '16 08:10 Hesesses

@Hesesses , this is how I fixed it:

.ui-select-placeholder, .ui-select-match-text, .ui-select-match-item {
 	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	padding-right: 40px;
}

DenisaSurdu avatar Dec 08 '16 15:12 DenisaSurdu

I've noticed a case in which this solution doesn't work...

Put the ui-select inside an input-group:

 <div class="input-group">
    <!-- ui select here... -->
    <span class="input-group-addon"><a href="" ng-click="selectedItem.selected = undefined" title="Clear"><span class="glyphicon glyphicon-remove"></span></a></span>
 </div>

I typically use these input-groups for optional selection.

Here is a screenshot within and without input-group

image

...Any help? thanks

EDIT: I've created a Plunkr: http://plnkr.co/edit/EWCTGawhdNIDQApaCBf9?p=preview

germanger avatar Jan 30 '17 19:01 germanger

I use the theme select2, ui-select doesn't even show the option with large text. I think it also have an issue with the theme selected

lacivert avatar Feb 18 '17 12:02 lacivert

can this issue be opened? the Plunkr I created shows pretty clear that this is not solved

germanger avatar Mar 20 '17 05:03 germanger

Sure, could you also investigate the issue and maybe make a PR or provide enough information so that somebody can make the PR?

Jefiozie avatar Mar 20 '17 16:03 Jefiozie

input-group class sets display: table; style in bootstrap css. So it's breaks element... Still can't find good solution to fix this.

halofourteen avatar Mar 23 '17 10:03 halofourteen

@Hesesses another possibility can be:

.ui-select-placeholder,.ui-select-match-text,.ui-select-match-item{
  width: 100%;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  padding-right: 20px;
}


.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{
    width: auto;
    padding-right: 5px;
}

to fix label or tag width.

kevinah95 avatar Aug 23 '17 18:08 kevinah95

<ui-select ng-model="selectedReceiver.selected" ng-disabled="fetchingReceivers || receivers.length == 0">
    <ui-select-match placeholder="">{{$select.selected.code}} - {{$select.selected.name}}</ui-select-match>
    <ui-select-choices repeat="receiver in receivers | filterBy: ['name', 'code']: $select.search"> 
        <div ng-bind-html="receiver.name | highlight: $select.search"></div>
        <small>Code: <span ng-bind-html="receiver.code | highlight: $select.search"></span></small>
        <hr style="margin-top: 0px; margin-bottom: 0px; border-top: 1px solid #C0C0C0;"/>
    </ui-select-choices>
</ui-select>

I am using 0.18.1 angular. How to fix the overflow text. note: I am restricted not to update angular.

harshikesh avatar Sep 28 '17 13:09 harshikesh

Using text-overflow: ellipsis; is fine but I want to view the text which is over flowing. How can I do that ? Can we use any tool tip kind of option so that when we hover we can see the whole text?

578305 avatar Jun 17 '19 10:06 578305

title tag?

blowsie avatar Jun 17 '19 15:06 blowsie