I
I
Ivan Volkov2017-05-09 23:57:57
React
Ivan Volkov, 2017-05-09 23:57:57

How to remove scroll to active component in React?

Good evening. Tell me why this is happening.
I have a controller component

class CasesController extends React.Component {
    constructor(props) {
        super(props);
    }

    sortCasesPriority(caseA, caseB) {
        if (caseA.comeLater > caseB.comeLater) return 1;
        if (caseB.comeLater > caseA.comeLater) return -1;
        if (caseA.comeLater == caseB.comeLater) {
            if (caseA.priority > caseB.priority) return -1;
            if (caseB.priority > caseA.priority) return 1;
        }
    }

    render() {
        const {cases} = this.props;
        return (
            cases.sort(this.sortCasesPriority).map(singleCase => {
                    return (
                        <Case
                            key={singleCase.id}
                            singleCase={singleCase}
                        />
                    )
                }
            ))
    }
}

in which Case are drawn.
by default, all Cases have comeLater = 0. The Case has a button that changes comeLater to 1. Accordingly (this is how the sort function is set), the element is moved to the very bottom of the list. But the browser window also follows it and scrolls to the very bottom of the page. What is it and how can it be changed?
PS
action and reducer to change comeLater
export function comeLaterCase(caseId){
    return{
        type: COME_LATER_CASE,
        payload: caseId
    }
}
case COME_LATER_CASE:
            //изменяем только тот элемент, где совпал ID
            let newLaterCases = state.cases.filter(singleCase => {
                if (singleCase.id == action.payload)
                    singleCase.comeLater = ++singleCase.comeLater;
                return singleCase;
            });
            return {...state, cases: newLaterCases};

the Case component, which just has a button to change comeLater.
class Case extends React.Component {
    constructor(props) {
        super(props);

        const {singleCase} = this.props;
        this.singleCase = singleCase;
        this.handleComeLaterButton = this.handleComeLaterButton.bind(this);
    }

    handleComeLaterButton(){
        const {comeLaterCase} = this.props.casesActions;
        comeLaterCase(this.singleCase.id);
    }

    render() {
        const {singleCase} = this.props;
        return (
            <div className="singleCase">
                <div>
                {singleCase.text}
                </div>
                <div>
                    <RaisedButton label="Игнорировать" onTouchTap={this.handleComeLaterButton}/>
                </div>
            </div>
        )
    }
}

And yes, there are routes
ReactDOM.render(
    <Provider store={store}>
            <HashRouter>
                <MuiThemeProvider muiTheme={getMuiTheme(darkBaseTheme)}>
                    <div className="App">
                        <ul className="menu-bar">
                            <li className="menu-item"><Link className="menu-item-link" to="/">Главная</Link></li>
                            <li className="menu-item"><Link className="menu-item-link" to="/cases">Кейсы</Link></li>
                        </ul>
                        <Route exact path="/" component={App} />
                        <Route path="/cases" component={CasesController} />
                    </div>
                </MuiThemeProvider>
            </HashRouter>
    </Provider>,
    document.getElementById("container")
);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question