mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-19 20:09:35 +00:00
remove redundant menuOffsetX
This commit is contained in:
parent
cff16e5d7d
commit
047865368a
2 changed files with 1 additions and 11 deletions
|
@ -26,7 +26,6 @@
|
||||||
const position = writable([x, y]);
|
const position = writable([x, y]);
|
||||||
const currentIndex = writable(-1);
|
const currentIndex = writable(-1);
|
||||||
const hasPopup = writable(false);
|
const hasPopup = writable(false);
|
||||||
const menuOffsetX = writable(0);
|
|
||||||
const ctx = getContext("ContextMenu");
|
const ctx = getContext("ContextMenu");
|
||||||
|
|
||||||
let options = [];
|
let options = [];
|
||||||
|
@ -45,7 +44,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
setContext("ContextMenu", {
|
setContext("ContextMenu", {
|
||||||
menuOffsetX,
|
|
||||||
currentIndex,
|
currentIndex,
|
||||||
position,
|
position,
|
||||||
close,
|
close,
|
||||||
|
@ -91,8 +89,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (open || y === 0) {
|
if (open || y === 0) {
|
||||||
menuOffsetX.set(e.x);
|
|
||||||
|
|
||||||
if (window.innerHeight - height < e.y) {
|
if (window.innerHeight - height < e.y) {
|
||||||
y = e.y - height;
|
y = e.y - height;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -70,16 +70,11 @@
|
||||||
let role = "menuitem";
|
let role = "menuitem";
|
||||||
let submenuOpen = false;
|
let submenuOpen = false;
|
||||||
let submenuPosition = [0, 0];
|
let submenuPosition = [0, 0];
|
||||||
let menuOffsetX = 0;
|
|
||||||
|
|
||||||
const unsubPosition = ctx.position.subscribe((position) => {
|
const unsubPosition = ctx.position.subscribe((position) => {
|
||||||
rootMenuPosition = position;
|
rootMenuPosition = position;
|
||||||
});
|
});
|
||||||
|
|
||||||
const unsubMenuOffsetX = ctx.menuOffsetX.subscribe((_menuOffsetX) => {
|
|
||||||
menuOffsetX = _menuOffsetX;
|
|
||||||
});
|
|
||||||
|
|
||||||
function handleClick(opts = {}) {
|
function handleClick(opts = {}) {
|
||||||
if (disabled) return ctx.close();
|
if (disabled) return ctx.close();
|
||||||
if (subOptions) return;
|
if (subOptions) return;
|
||||||
|
@ -117,7 +112,6 @@
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
unsubPosition();
|
unsubPosition();
|
||||||
unsubMenuOffsetX();
|
|
||||||
if (unsubCurrentIds) unsubCurrentIds();
|
if (unsubCurrentIds) unsubCurrentIds();
|
||||||
if (unsubCurrentId) unsubCurrentId();
|
if (unsubCurrentId) unsubCurrentId();
|
||||||
if (typeof timeoutHover === "number") clearTimeout(timeoutHover);
|
if (typeof timeoutHover === "number") clearTimeout(timeoutHover);
|
||||||
|
@ -132,7 +126,7 @@
|
||||||
const { width, y } = ref.getBoundingClientRect();
|
const { width, y } = ref.getBoundingClientRect();
|
||||||
let x = rootMenuPosition[0] + width;
|
let x = rootMenuPosition[0] + width;
|
||||||
|
|
||||||
if (window.innerWidth - menuOffsetX < width) {
|
if (window.innerWidth - rootMenuPosition[0] < width) {
|
||||||
x = rootMenuPosition[0] - width;
|
x = rootMenuPosition[0] - width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue