summaryrefslogtreecommitdiffstats
path: root/webapp/components/rhs_dropdown.jsx
blob: 9c0f4d7b14eb39d5c2ab5ab477d21ac36a426667 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import * as Agent from 'utils/user_agent.jsx';
import RhsDropdownMenu from 'components/rhs_dropdown_menu.jsx';

import {Dropdown} from 'react-bootstrap';
import React from 'react';

export default class RhsDropdown extends React.Component {
    constructor(props) {
        super(props);

        this.toggleDropdown = this.toggleDropdown.bind(this);

        this.state = {
            showDropdown: false
        };
    }

    toggleDropdown() {
        const showDropdown = !this.state.showDropdown;
        if (Agent.isMobile() || Agent.isMobileApp()) {
            const scroll = document.querySelector('.scrollbar--view');
            if (showDropdown) {
                scroll.style.overflow = 'hidden';
            } else {
                scroll.style.overflow = 'scroll';
            }
        }

        this.setState({showDropdown});
    }

    render() {
        return (
            <Dropdown
                id='rhs_dropdown'
                open={this.state.showDropdown}
                onToggle={this.toggleDropdown}
            >
                <a
                    href='#'
                    className='post__dropdown dropdown-toggle'
                    bsRole='toggle'
                    onClick={this.toggleDropdown}
                />
                <RhsDropdownMenu>
                    {this.props.dropdownContents}
                </RhsDropdownMenu>
            </Dropdown>
        );
    }
}

RhsDropdown.propTypes = {
    dropdownContents: React.PropTypes.array.isRequired
};