-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit reworks the dropdown implementation. The old implementation did not allow users to define an explicit order of the values (amap only). Also the custom TriggerDropdown, DropdownConfig, and DropdownMode types were unwieldy. The new API provides a few variants with simple parameters.
- Loading branch information
Showing
10 changed files
with
444 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
455 changes: 249 additions & 206 deletions
455
src/Aardvark.UI.Primitives/Primitives/SimplePrimitives.fs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
if (!aardvark.dropdown) { | ||
/** | ||
* @param {*} x | ||
* @param {*} y | ||
*/ | ||
function arraysIdentical(x, y) { | ||
const a = Array.isArray(x) ? x : [x]; | ||
const b = Array.isArray(y) ? y : [y]; | ||
let i = a.length; | ||
if (i != b.length) return false; | ||
while (i--) { | ||
if (a[i] !== b[i]) return false; | ||
} | ||
return true; | ||
}; | ||
|
||
/** | ||
* @param {HTMLElement[]} $self | ||
* @param {string} trigger | ||
* @param {{onmessage: function}} channel | ||
*/ | ||
aardvark.dropdown = function ($self, trigger, channel) { | ||
$self.dropdown({ | ||
on: trigger, | ||
onChange: function (value) { aardvark.processEvent($self[0].id, 'data-event', value); } | ||
}); | ||
|
||
channel.onmessage = function(values) { | ||
const curr = $self.dropdown('get values'); | ||
|
||
// Prevent resetting the same values (leads to flickering) | ||
if (arraysIdentical(curr, values)) { | ||
return; | ||
} | ||
|
||
$self.dropdown('clear', true); | ||
$self.dropdown('set selected', values, true); // set exactly bugged? clear seems to trigger event | ||
}; | ||
}; | ||
} |
Oops, something went wrong.