Skip to content

Commit 08638a6

Browse files
authored
Merge branch 'main' into lunny/actions_log_api
2 parents e712ff0 + c7b85f7 commit 08638a6

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

web_src/js/modules/fomantic/dropdown.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ export function initAriaDropdownPatch() {
2121
function ariaDropdownFn(this: any, ...args: Parameters<FomanticInitFunction>) {
2222
const ret = fomanticDropdownFn.apply(this, args);
2323

24-
for (const el of this) {
24+
for (let el of this) {
25+
// dropdown will replace '<select class="ui dropdown"/>' to '<div class="ui dropdown"><select (hidden)></select><div class="menu">...</div></div>'
26+
// so we need to correctly find the closest '.ui.dropdown' element, it is the real fomantic dropdown module.
27+
el = el.closest('.ui.dropdown');
2528
if (!el[ariaPatchKey]) {
2629
// the elements don't belong to the dropdown "module" and won't be reset
2730
// so we only need to initialize them once.
2831
attachInitElements(el);
2932
}
3033

31-
// if the `$().dropdown()` call is without arguments, or it has non-string (object) argument,
34+
// if the `$().dropdown()` is called without arguments, or it has non-string (object) argument,
3235
// it means that such call will reset the dropdown "module" including internal settings,
3336
// then we need to re-delegate the callbacks.
3437
const $dropdown = $(el);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {weakRefClass} from './polyfills.ts';
2+
3+
test('polyfillWeakRef', () => {
4+
const WeakRef = weakRefClass();
5+
const r = new WeakRef(123);
6+
expect(r.deref()).toEqual(123);
7+
});

web_src/js/webcomponents/polyfills.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,19 @@ try {
1616
return intlNumberFormat(locales, options);
1717
};
1818
}
19+
20+
export function weakRefClass() {
21+
const weakMap = new WeakMap();
22+
return class {
23+
constructor(target: any) {
24+
weakMap.set(this, target);
25+
}
26+
deref() {
27+
return weakMap.get(this);
28+
}
29+
};
30+
}
31+
32+
if (!window.WeakRef) {
33+
window.WeakRef = weakRefClass() as any;
34+
}

0 commit comments

Comments
 (0)