@startlibs/components 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startlibs/components",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Startlibs Components",
5
5
  "main": "lib/index.cjs",
6
6
  "exports": {
@@ -241,7 +241,7 @@ export class SimpleLi extends React.Component {
241
241
  }
242
242
 
243
243
  componentDidUpdate() {
244
- if (this.props.hover) {
244
+ if (this.props.hover && this.props.scrollOnHover !== false) {
245
245
  this.scrollToVisibility()
246
246
  }
247
247
  }
@@ -288,7 +288,7 @@ export class SimpleLi extends React.Component {
288
288
  }
289
289
 
290
290
  render() {
291
- const {label, layerIndex, href, linkTo, prefixWith, subMenu, icon, children, ...rest} = this.props
291
+ const {label, layerIndex, href, linkTo, prefixWith, subMenu, icon, children, scrollOnHover, ...rest} = this.props
292
292
  const Tag = (linkTo) ? Link : 'a'
293
293
  return <ListItem
294
294
  {...rest}
@@ -306,7 +306,7 @@ export class SimpleLi extends React.Component {
306
306
  }
307
307
  }
308
308
 
309
- export const Li = React.forwardRef(({emitter = mitt(), index, menuSlot, keepOpen, hover, layerIndex, hoverCursor, passTouchThrough, children, setCursorOnHover, onClick, prefixWith, linkTo, icon, label,descText,helpText, target, href, ...rest},ref) => {
309
+ export const Li = React.forwardRef(({emitter = mitt(), index, menuSlot, keepOpen, hover, layerIndex, hoverCursor, scrollOnHover, passTouchThrough, children, setCursorOnHover, onClick, prefixWith, linkTo, icon, label,descText,helpText, target, href, ...rest},ref) => {
310
310
  const nodeRef = useEnsureRef(ref)
311
311
  const tagRef = useRef()
312
312
  const subMenu = useToggle()
@@ -332,7 +332,7 @@ export const Li = React.forwardRef(({emitter = mitt(), index, menuSlot, keepOpen
332
332
  }
333
333
 
334
334
  useEffect(() => {
335
- if (hover) {
335
+ if (hover && scrollOnHover !== false) {
336
336
  try {
337
337
  const el = nodeRef.current
338
338
  const parent = el.parentElement
@@ -468,6 +468,9 @@ export const ContextMenuComponent = forwardRef((
468
468
  ) => {
469
469
  const ref = useEnsureRef(unesuredRef)
470
470
  const [hoverCursor, setHoverCursor] = useState(autoHover || sub ? 0 : -1)
471
+ // Hover vindo do mouse não deve rolar a lista: o Chrome dispara mousemove sintético
472
+ // ao fim do scroll, e o item cortado sob o cursor puxaria a lista de volta.
473
+ const hoverFromMouse = useRef(false)
471
474
  const [layerCursor, setLayerCursor] = useContextMenuSharedState(0)
472
475
 
473
476
  const [layerIndex, {getSize}] = useContextMenuLayers()
@@ -483,6 +486,7 @@ export const ContextMenuComponent = forwardRef((
483
486
 
484
487
  useEffect(() => {
485
488
  if (hoverIndex !== undefined) {
489
+ if (hoverIndex !== hoverCursor) hoverFromMouse.current = false
486
490
  setHoverCursor(Math.min(Math.max(hoverIndex, -1), getTotalKeyboardItems(children) + 1))
487
491
  }
488
492
  }, [hoverIndex !== hoverCursor])
@@ -509,6 +513,7 @@ export const ContextMenuComponent = forwardRef((
509
513
  const direction = e.keyCode - 39
510
514
  const max = getTotalKeyboardItems(children)
511
515
  const newIndex = (hoverCursor + direction + max) % max
516
+ hoverFromMouse.current = false
512
517
  setHoverCursor(newIndex)
513
518
  onHover(newIndex)
514
519
  }
@@ -531,6 +536,7 @@ export const ContextMenuComponent = forwardRef((
531
536
  }
532
537
 
533
538
  const setCursorOnHover = (index) => {
539
+ hoverFromMouse.current = true
534
540
  setLayerCursor(layerIndex)
535
541
  setHoverCursor(index)
536
542
  onHover(index)
@@ -547,6 +553,7 @@ export const ContextMenuComponent = forwardRef((
547
553
  fixedPosition:props.fixed,
548
554
  hover: hoverCursor === indexRef.current && layerIndex === layerCursor,
549
555
  hoverCursor: hoverCursor,
556
+ scrollOnHover: !hoverFromMouse.current,
550
557
  index: indexRef.current++,
551
558
  setCursorOnHover,
552
559
  emitter: itemsEmitter,