Skip to content

Commit

Permalink
fix(menu): height wrong calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Jan 15, 2024
1 parent 1cc5d30 commit 903362b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion index.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
},
"menu": {
"icon": true,
"version": "0.1.1",
"version": "0.1.2",
"style": true,
"test": true,
"install": false,
Expand Down
21 changes: 15 additions & 6 deletions src/menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import $ from 'licia/$'
import h from 'licia/h'
import defaults from 'licia/defaults'
import each from 'licia/each'
import { measuredScrollbarWidth, hasVerticalScrollbar } from '../share/util'
import nextTick from 'licia/nextTick'
import {
measuredScrollbarWidth,
hasVerticalScrollbar,
exportCjs,
} from '../share/util'

/**
* Simple menu.
Expand Down Expand Up @@ -71,7 +76,10 @@ export default class Menu extends Component {
$glassPane.append(this.container)
$glassPane.show()

this.positionContent(x, y, parent)
// Delay a little to make sure height calculation is correct.
nextTick(() => {
this.positionContent(x, y, parent)
})
}
destroy() {
this.hide()
Expand Down Expand Up @@ -134,7 +142,7 @@ export default class Menu extends Component {
private showSubMenu(subMenu: Menu, $el: $.$) {
const { left, width, top } = $el.offset()

let x = left + width
let x = left + width + 1
if (hasVerticalScrollbar(this.container)) {
x += measuredScrollbarWidth()
}
Expand Down Expand Up @@ -229,9 +237,6 @@ export default class Menu extends Component {
}
}

module.exports = Menu
module.exports.default = Menu

/** IMenuItemOptions */
export interface IMenuItemOptions {
/** Menu type. */
Expand All @@ -243,3 +248,7 @@ export interface IMenuItemOptions {
/** Click event handler. */
click?: () => void
}

if (typeof module !== 'undefined') {
exportCjs(module, Menu)
}
2 changes: 1 addition & 1 deletion src/menu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "menu",
"version": "0.1.1",
"version": "0.1.2",
"description": "Simple menu",
"luna": {
"icon": true
Expand Down

0 comments on commit 903362b

Please sign in to comment.