Giter VIP home page Giter VIP logo

Comments (23)

asmyshlyaev177 avatar asmyshlyaev177 commented on August 25, 2024

Hm, very recently i implement this. 0.2.9 version, 0.3.2 is latest. Can you check again or help reproduce issue on jsbin or somewhere?

from react-horizontal-scrolling-menu.

zverexe avatar zverexe commented on August 25, 2024

I have the same issue, I cannot programmatically, without click change active tab

from react-horizontal-scrolling-menu.

asmyshlyaev177 avatar asmyshlyaev177 commented on August 25, 2024

Ok, what happen if update parent component?

Select it in react console and update
$r.forceUpdate()

from react-horizontal-scrolling-menu.

zverexe avatar zverexe commented on August 25, 2024

what should I update? I have 2 components, redux store in which I store the name of active item. If I change this name in redux, it didn't change in the scrollable menu, but in the selected property goes correct data

from react-horizontal-scrolling-menu.

asmyshlyaev177 avatar asmyshlyaev177 commented on August 25, 2024

Can you reproduce it?

from react-horizontal-scrolling-menu.

zverexe avatar zverexe commented on August 25, 2024

I will try to reproduce tomorrow but idea is to change tab during certain condition. For example I setState item with number 1 and give it to selected prop of menu and it should change it. But it changes it only if I click on the item

from react-horizontal-scrolling-menu.

zverexe avatar zverexe commented on August 25, 2024
const list = [
  { name: 'item1' },
  { name: 'item2' },
  { name: 'item3' },
  { name: 'item4' },
  { name: 'item5' },
  { name: 'item6' },
  { name: 'item7' },
  { name: 'item8' },
  { name: 'item9' },
  { name: 'item10' },
  { name: 'item11' },
  { name: 'item12' },
  { name: 'item13' },
  { name: 'item14' },
  { name: 'item15' },
  { name: 'item16' },
  { name: 'item17' },
  { name: 'item18' },
  { name: 'item19' },
  { name: 'item20' },
  { name: 'item21' },
  { name: 'item22' },
  { name: 'item23' },
  { name: 'item24' },
  { name: 'item25' }
];

const MenuItem = ({ text, selected }) => {
  return (
      <div
          className={`${Styles.menu_item} ${selected ? Styles.active : ''}`}
      >
        {text}
      </div>
  );
};

export const Menu = (list) => list.map(el => {
  const { name } = el;

  return (
      <MenuItem
          text={name}
          key={name}
      />
  );
});

const Arrow = ({ text, className }) => {
  return (
      <div
          className={className}
      >{text}</div>
  );
};

export const ArrowLeft = Arrow({ text: '<', className: 'arrow-prev' });
export const ArrowRight = Arrow({ text: '>', className: 'arrow-next' });


class TabComponent extends Component {

  constructor(props) {
    super(props);
    this.menu = null;

    this.state = {
      selected: 'item1',
      itemsCount: list.length,
      translate: 0,
      alignCenter: true,
      dragging: true,
      clickWhenDrag: false,
      transition: 0.4,
      wheel: true
    };
    this.menuItems = Menu(list.slice(0, list.length), this.state.selected);
  }

  onUpdate = ({ translate }) => {
    console.log(`onUpdate: translate: ${translate}`);
    this.setState({ translate });
  }

  onSelect = key => {
    console.log(`onSelect: ${key}`);
    this.setState({ selected: key });
  }

  componentDidUpdate(prevProps, prevState) {
    const { alignCenter } = prevState;
    const {
      alignCenter: alignCenterNew
    } = this.state;
    if (alignCenter !== alignCenterNew) {
      this.menu.setInitial();
    }
  }

  setItemsCount = ev => {
    const { itemsCount = list.length, selected } = this.state;
    const val = +ev.target.value;
    const itemsCountNew = !isNaN(val) && val <= list.length && val >= 0
        ? +ev.target.value
        : list.length;
    const itemsCountChanged = itemsCount !== itemsCountNew;

    if (itemsCountChanged) {
      this.menuItems = Menu(list.slice(0, itemsCountNew), selected);
      this.setState({
        itemsCount: itemsCountNew});
    }
  }

  setSelected = ev => {
    const { value } = ev.target;
    this.setState({ selected: String(value) });
  }

  test = () => {
    console.log(`onSelect: item12`);
    this.setState({ selected: 'item12' });
  }

  render() {
    const {
      selected,
      translate,
      alignCenter,
      dragging,
      clickWhenDrag,
      transition,
      wheel,
      itemsCount
    } = this.state;

    const menu = this.menuItems;

    const checkboxStyle = {
      margin: '5px 10px'
    };
    const valueStyle = {
      margin: '5px 10px',
      display: 'inline-block'
    };
    return (
        <div className="App">
          <header className="App-header">

            <h1 onClick={this.test} className="App-title">React horizontal scrolling menu</h1>
          </header>
          <p className="App-intro" onClick={this.test}>
            Horizontal scrolling menu example.
            Click arrow or drag items.
          </p>
          <ScrollMenu
              ref={el => this.menu = el}
              data={menu}
              arrowLeft={ArrowLeft}
              arrowRight={ArrowRight}
              transition={+transition}
              onUpdate={this.onUpdate}
              onSelect={this.onSelect}
              selected={selected}
              translate={translate}
              alignCenter={alignCenter}
              dragging={false}
              clickWhenDrag={clickWhenDrag}
              wheel={wheel}
          />
        </div>
    )
  }
}

so using this snippet from your repo I can reproduce that bug. I want to set programatically active tab clicking on test onclick function, when I click state updates but tab item doesn't change

from react-horizontal-scrolling-menu.

asmyshlyaev177 avatar asmyshlyaev177 commented on August 25, 2024

Reproduce i mean create snipper here for example https://codesandbox.io

In demo project now can change selected item from parent component and it works.

clicking on test onclick function

Don't understand what you mean, need just pass new value in selected prop.

Example
It works, show exactly where is problem

from react-horizontal-scrolling-menu.

zverexe avatar zverexe commented on August 25, 2024

I need to add code snippet from my code that. I will add it tomorrow and share it

from react-horizontal-scrolling-menu.

asmyshlyaev177 avatar asmyshlyaev177 commented on August 25, 2024

Look at my example, "selected" text field, change 'item1' to 'item2' and selected item changes.

Anyway, i steel need working snippet when i can see problem, not text or description.
In my last message has link where you can easily create it.

from react-horizontal-scrolling-menu.

zverexe avatar zverexe commented on August 25, 2024

Yes, I saw this, but for some reason in my component it doesn't work. I will create code snippet tomorrow. Maybe the problem is because I set active menu item in one component and pass it into other component where actually menu is

from react-horizontal-scrolling-menu.

asmyshlyaev177 avatar asmyshlyaev177 commented on August 25, 2024

So need check passed props from your component and how it update, prop doesn't update or component doesn't update.

from react-horizontal-scrolling-menu.

zverexe avatar zverexe commented on August 25, 2024

I pass them via redux, they come to component for sure, I checked this but menu doesn't update

from react-horizontal-scrolling-menu.

asmyshlyaev177 avatar asmyshlyaev177 commented on August 25, 2024

Make repo where i can see problem.

from react-horizontal-scrolling-menu.

zverexe avatar zverexe commented on August 25, 2024

so I created sandbox here https://codesandbox.io/s/wyk4pn0vow but the thing is that in the sandbox everything working as expected but locally it isn't. I debugged everything and the thing is when I update selected menu item in state, state updates, Menu function running but MenuItem function isn't, item didn't changes through selected prop but state already contains changed menu item

from react-horizontal-scrolling-menu.

asmyshlyaev177 avatar asmyshlyaev177 commented on August 25, 2024

Sandbox is empty.
Try to update to latest version.

from react-horizontal-scrolling-menu.

zverexe avatar zverexe commented on August 25, 2024

https://codesandbox.io/s/wyk4pn0vow

from react-horizontal-scrolling-menu.

zverexe avatar zverexe commented on August 25, 2024

did you update the component?

from react-horizontal-scrolling-menu.

asmyshlyaev177 avatar asmyshlyaev177 commented on August 25, 2024

From 0.2.9 version must work.

from react-horizontal-scrolling-menu.

zverexe avatar zverexe commented on August 25, 2024

Yes, it was the reason. I used 0.2.7 version. Thanks

from react-horizontal-scrolling-menu.

markoffk avatar markoffk commented on August 25, 2024

Hi, asmyshlyaev177.
Sorry for delay in response.
It seems that your component is working. I just misunderstood behaviour of selecting items. As for me, if item is selected - the whole container should be scrolled until selected item becomes visible.
What do you think about it?

from react-horizontal-scrolling-menu.

asmyshlyaev177 avatar asmyshlyaev177 commented on August 25, 2024

Hi, already has issue about that, will implement later.

from react-horizontal-scrolling-menu.

zverexe avatar zverexe commented on August 25, 2024

I mentioned the same that @markoffk speaking about in this ticket #14

from react-horizontal-scrolling-menu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.