HomeOverflow content

Panels clip their content by default, to avoid showing scrollbars while resizing. Content can still be configured to overflow within a panel though. This example shows how.

1 // https://reactjs.org/tutorial/tutorial.html#completing-the-game
2 const root = ReactDOM.createRoot(document.getElementById("root"));
3 root.render(<Game />);
4
5 function calculateWinner(squares) {
6 const lines = [
7 [0, 1, 2],
8 [3, 4, 5],
9 [6, 7, 8],
10 [0, 3, 6],
11 [1, 4, 7],
12 [2, 5, 8],
13 [0, 4, 8],
14 [2, 4, 6],
15 ];
16 for (let i = 0; i < lines.length; i++) {
17 const [a, b, c] = lines[i];
18 if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
19 return squares[a];
20 }
21 }
22 return null;
23 }
1 function Square(props) {
2 return (
3 <button className="square" onClick={props.onClick}>
4 {props.value}
5 </button>
6 );
7 }
8
9 class Board extends React.Component {
10 renderSquare(i) {
11 return (
12 <Square
13 value={this.props.squares[i]}
14 onClick={() => this.props.onClick(i)}
15 />
16 );
17 }
18
19 render() {
20 return (
21 <div>
22 <div className="board-row">
23 {this.renderSquare(0)}
24 {this.renderSquare(1)}
25 {this.renderSquare(2)}
26 </div>
27 <div className="board-row">
28 {this.renderSquare(3)}
29 {this.renderSquare(4)}
30 {this.renderSquare(5)}
31 </div>
32 <div className="board-row">
33 {this.renderSquare(6)}
34 {this.renderSquare(7)}
35 {this.renderSquare(8)}
36 </div>
37 </div>
38 );
39 }
40 }
41
42 class Game extends React.Component {
43 constructor(props) {
44 super(props);
45 this.state = {
46 history: [
47 {
48 squares: Array(9).fill(null),
49 },
50 ],
51 stepNumber: 0,
52 xIsNext: true,
53 };
54 }
55
56 handleClick(i) {
57 const history = this.state.history.slice(0, this.state.stepNumber + 1);
58 const current = history[history.length - 1];
59 const squares = current.squares.slice();
60 if (calculateWinner(squares) || squares[i]) {
61 return;
62 }
63 squares[i] = this.state.xIsNext ? "X" : "O";
64 this.setState({
65 history: history.concat([
66 {
67 squares: squares,
68 },
69 ]),
70 stepNumber: history.length,
71 xIsNext: !this.state.xIsNext,
72 });
73 }
74
75 jumpTo(step) {
76 this.setState({
77 stepNumber: step,
78 xIsNext: step % 2 === 0,
79 });
80 }
81
82 render() {
83 const history = this.state.history;
84 const current = history[this.state.stepNumber];
85 const winner = calculateWinner(current.squares);
86
87 const moves = history.map((step, move) => {
88 const desc = move ? "Go to move #" + move : "Go to game start";
89 return (
90 <li key={move}>
91 <button onClick={() => this.jumpTo(move)}>{desc}</button>
92 </li>
93 );
94 });
95
96 let status;
97 if (winner) {
98 status = "Winner: " + winner;
99 } else {
100 status = "Next player: " + (this.state.xIsNext ? "X" : "O");
101 }
102
103 return (
104 <div className="game">
105 <div className="game-board">
106 <Board
107 squares={current.squares}
108 onClick={(i) => this.handleClick(i)}
109 />
110 </div>
111 <div className="game-info">
112 <div>{status}</div>
113 <ol>{moves}</ol>
114 </div>
115 </div>
116 );
117 }
118 }
1 <PanelGroup direction="horizontal">
2 <Panel>
3 <div style="overflow: auto">
4 {/* Content */}
5 </div>
6 </Panel>
7 <PanelResizeHandle />
8 <Panel>
9 <div style="overflow: auto">
10 {/* Content */}
11 </div>
12 </Panel>
13 </PanelGroup>