Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevents event bubbling in child elements of SelectableGroup #55

Open
monsterooo opened this issue Aug 6, 2019 · 0 comments
Open

Prevents event bubbling in child elements of SelectableGroup #55

monsterooo opened this issue Aug 6, 2019 · 0 comments

Comments

@monsterooo
Copy link

Hi, @valerybugakov

I tried to prevent bubbling of child elements in the program.

import React from 'react'
import { createSelectable } from '../src'
import Label from './Label'

// No one method works
function onMousedown(e) {
  e.stopPropagation()
  e.preventDefault()
  e.nativeEvent.stopPropagation()
  e.nativeEvent.preventDefault()
  e.nativeEvent.stopImmediatePropagation()
}
const Album = ({
  selectableRef, selected, selecting, title, year,
}) => (
  <div
    ref={selectableRef}
    className={`
      ${(year === 10 || year === 27) && 'not-selectable'}
      item
      ${selecting && 'selecting'}
      ${selected && 'selected'}
    `}
    onMouseDown={onMousedown}
  >
    <div className="tick">+</div>
    <h2>{title}</h2>
    <small>{year}</small>
    <Label selected={selected} selecting={selecting} />
  </div>
)

export default createSelectable(Album)

I looked at the source code

SelectableGroup Event bind

I made the following attempt

// src/SelectableGroup.js
render() {
    return (
      <SelectableGroupContext.Provider value={this.contextValue}>
        <this.props.component
          ref={this.getGroupRef}
          onMouseDown={this.mouseDown}  {/** It works fine **/}
          style={Object.assign({}, this.defaultContainerStyle, this.props.style)}
          className={`${this.props.className} ${
            this.state.selectionMode ? this.props.selectionModeClass : ''
          }`}
        >
          <Selectbox
            ref={this.getSelectboxRef}
            fixedPosition={this.props.fixedPosition}
            className={this.props.selectboxClassName}
          />
          {this.props.children}
        </this.props.component>
      </SelectableGroupContext.Provider>
    )
  }

Do you think you can make some minor adjustments?

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant