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

Fix RTL support when using tagging - calculate right input width #1375

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,21 @@ uis.controller('uiSelectCtrl',
if (containerWidth === 0) {
return false;
}
var inputWidth = containerWidth - input.offsetLeft - 10;

// Check if document is rtl
var isRTL = angular.element('html[dir="rtl"]').length > 0,
inputWidth;

// If document is RTL - calculate offset right
if (isRTL) {
var offsetRight = containerWidth - (input.offsetLeft + ctrl.searchInput.outerWidth());
inputWidth = containerWidth - offsetRight - 10;
}

else {
inputWidth = containerWidth - input.offsetLeft - 10;
}

if (inputWidth < 50) inputWidth = containerWidth;
ctrl.searchInput.css('width', inputWidth+'px');
return true;
Expand Down
9 changes: 5 additions & 4 deletions src/uiSelectMultipleDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
}
// Handles selected options in "multiple" mode
function _handleMatchSelection(key){
var caretPosition = _getCaretPosition($select.searchInput[0]),
var isRTL = angular.element('html[dir="rtl"]').length > 0,
caretPosition = _getCaretPosition($select.searchInput[0]),
length = $select.selected.length,
// none = -1,
first = 0,
Expand All @@ -204,19 +205,19 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
prev = $selectMultiple.activeMatchIndex-1,
newIndex = curr;

if(caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) return false;
if(caretPosition > 0 || ($select.search.length && key == (isRTL ? KEY.LEFT : KEY.RIGHT))) return false;

$select.close();

function getNewActiveMatchIndex(){
switch(key){
case KEY.LEFT:
case (isRTL ? KEY.RIGHT : KEY.LEFT):
// Select previous/first item
if(~$selectMultiple.activeMatchIndex) return prev;
// Select last item
else return last;
break;
case KEY.RIGHT:
case (isRTL ? KEY.LEFT : KEY.RIGHT):
// Open drop-down
if(!~$selectMultiple.activeMatchIndex || curr === last){
$select.activate();
Expand Down