remove explicit store subscription

This commit is contained in:
Moritz Bischof 2021-05-03 17:44:13 +02:00
commit 92d1eba45c

View file

@ -58,23 +58,20 @@
const ctxGroup = getContext("ContextMenuGroup");
const ctxRadioGroup = getContext("ContextMenuRadioGroup");
const rootMenuPosition = ctx.position;
// "moderate-01" duration (ms) from Carbon motion recommended for small expansion, short distance movements
const moderate01 = 150;
let unsubCurrentIds = undefined;
let unsubCurrentId = undefined;
let timeoutHover = undefined;
let rootMenuPosition = [0, 0];
let focusIndex = 0;
let options = [];
let role = "menuitem";
let submenuOpen = false;
let submenuPosition = [0, 0];
const unsubPosition = ctx.position.subscribe((position) => {
rootMenuPosition = position;
});
function handleClick(opts = {}) {
if (disabled) return ctx.close();
if (subOptions) return;
@ -111,7 +108,6 @@
}
return () => {
unsubPosition();
if (unsubCurrentIds) unsubCurrentIds();
if (unsubCurrentId) unsubCurrentId();
if (typeof timeoutHover === "number") clearTimeout(timeoutHover);
@ -123,11 +119,12 @@
$: subOptions = $$slots.default;
$: ctx.setPopup(submenuOpen);
$: if (submenuOpen) {
const rootMenuX = $rootMenuPosition[0];
const { width, y } = ref.getBoundingClientRect();
let x = rootMenuPosition[0] + width;
let x = rootMenuX + width;
if (window.innerWidth - rootMenuPosition[0] < width) {
x = rootMenuPosition[0] - width;
if (window.innerWidth - rootMenuX < width) {
x = rootMenuX - width;
}
submenuPosition = [x, y];