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