mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 11:36:36 +00:00
remove explicit store subscription
This commit is contained in:
parent
fd09e96f71
commit
92d1eba45c
1 changed files with 6 additions and 9 deletions
|
@ -58,23 +58,20 @@
|
||||||
const ctxGroup = getContext("ContextMenuGroup");
|
const ctxGroup = getContext("ContextMenuGroup");
|
||||||
const ctxRadioGroup = getContext("ContextMenuRadioGroup");
|
const ctxRadioGroup = getContext("ContextMenuRadioGroup");
|
||||||
|
|
||||||
|
const rootMenuPosition = ctx.position;
|
||||||
|
|
||||||
// "moderate-01" duration (ms) from Carbon motion recommended for small expansion, short distance movements
|
// "moderate-01" duration (ms) from Carbon motion recommended for small expansion, short distance movements
|
||||||
const moderate01 = 150;
|
const moderate01 = 150;
|
||||||
|
|
||||||
let unsubCurrentIds = undefined;
|
let unsubCurrentIds = undefined;
|
||||||
let unsubCurrentId = undefined;
|
let unsubCurrentId = undefined;
|
||||||
let timeoutHover = undefined;
|
let timeoutHover = undefined;
|
||||||
let rootMenuPosition = [0, 0];
|
|
||||||
let focusIndex = 0;
|
let focusIndex = 0;
|
||||||
let options = [];
|
let options = [];
|
||||||
let role = "menuitem";
|
let role = "menuitem";
|
||||||
let submenuOpen = false;
|
let submenuOpen = false;
|
||||||
let submenuPosition = [0, 0];
|
let submenuPosition = [0, 0];
|
||||||
|
|
||||||
const unsubPosition = ctx.position.subscribe((position) => {
|
|
||||||
rootMenuPosition = position;
|
|
||||||
});
|
|
||||||
|
|
||||||
function handleClick(opts = {}) {
|
function handleClick(opts = {}) {
|
||||||
if (disabled) return ctx.close();
|
if (disabled) return ctx.close();
|
||||||
if (subOptions) return;
|
if (subOptions) return;
|
||||||
|
@ -111,7 +108,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
unsubPosition();
|
|
||||||
if (unsubCurrentIds) unsubCurrentIds();
|
if (unsubCurrentIds) unsubCurrentIds();
|
||||||
if (unsubCurrentId) unsubCurrentId();
|
if (unsubCurrentId) unsubCurrentId();
|
||||||
if (typeof timeoutHover === "number") clearTimeout(timeoutHover);
|
if (typeof timeoutHover === "number") clearTimeout(timeoutHover);
|
||||||
|
@ -123,11 +119,12 @@
|
||||||
$: subOptions = $$slots.default;
|
$: subOptions = $$slots.default;
|
||||||
$: ctx.setPopup(submenuOpen);
|
$: ctx.setPopup(submenuOpen);
|
||||||
$: if (submenuOpen) {
|
$: if (submenuOpen) {
|
||||||
|
const rootMenuX = $rootMenuPosition[0];
|
||||||
const { width, y } = ref.getBoundingClientRect();
|
const { width, y } = ref.getBoundingClientRect();
|
||||||
let x = rootMenuPosition[0] + width;
|
let x = rootMenuX + width;
|
||||||
|
|
||||||
if (window.innerWidth - rootMenuPosition[0] < width) {
|
if (window.innerWidth - rootMenuX < width) {
|
||||||
x = rootMenuPosition[0] - width;
|
x = rootMenuX - width;
|
||||||
}
|
}
|
||||||
|
|
||||||
submenuPosition = [x, y];
|
submenuPosition = [x, y];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue