Skip to content

Suggested fix for strange whitespace behaviour #122

@jacquelinewheeler

Description

@jacquelinewheeler

Searching for multiple words, separated by a space, is not behaving properly. The width calculation for the internal input is not accounting for any additional width from any whitespace characters, so when a user enters a number of spaces, the text appears to scroll and get hidden to the left.

For example: if I enter the search term 'one two', the 'o' would end up being cut off to the left. This issue is happening on the selectize demo page.

The solution for this is to change the property for white-space from 'nowrap' to 'pre'. This will ensure that the dummy node that is being used to measure the width of the string will render all whitespace without truncating. This can be updated in the following function:

var measureString = function(str, $parent) {
var $test = $('').css({
position: 'absolute',
top: -99999,
left: -99999,
width: 'auto',
padding: 0,
whiteSpace: 'pre'
}).text(str).appendTo('body');
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions