Commit 824a9a85 by Torkel Ödegaard Committed by GitHub

Merge pull request #14890 from grafana/14871-unit-picker-scroll-issue

fix: It should be possible to scroll in the unit picker before select…
parents 45a08792 d59f1fe6
......@@ -141,6 +141,9 @@ export function dropdownTypeahead2($compile) {
link: ($scope, elem, attrs) => {
const $input = $(inputTemplate);
const $button = $(buttonTemplate);
const timeoutId = {
blur: null
};
$input.appendTo(elem);
$button.appendTo(elem);
......@@ -177,6 +180,14 @@ export function dropdownTypeahead2($compile) {
[]
);
const closeDropdownMenu = () => {
$input.hide();
$input.val('');
$button.show();
$button.focus();
elem.removeClass('open');
};
$scope.menuItemSelected = (index, subIndex) => {
const menuItem = $scope.menuItems[index];
const payload: any = { $item: menuItem };
......@@ -184,6 +195,7 @@ export function dropdownTypeahead2($compile) {
payload.$subItem = menuItem.submenu[subIndex];
}
$scope.dropdownTypeaheadOnSelect(payload);
closeDropdownMenu();
};
$input.attr('data-provide', 'typeahead');
......@@ -223,16 +235,15 @@ export function dropdownTypeahead2($compile) {
elem.toggleClass('open', $input.val() === '');
});
elem.mousedown((evt: Event) => {
evt.preventDefault();
timeoutId.blur = null;
});
$input.blur(() => {
$input.hide();
$input.val('');
$button.show();
$button.focus();
// clicking the function dropdown menu won't
// work if you remove class at once
setTimeout(() => {
elem.removeClass('open');
}, 200);
timeoutId.blur = setTimeout(() => {
closeDropdownMenu();
}, 1);
});
$compile(elem.contents())($scope);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment