Skip to content

Commit

Permalink
ui(terminal history): scroll to bottom input when off screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ctaylo21 committed Jul 16, 2019
1 parent d65f80c commit 457e995
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 66 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## 0.6.2 - 2019-07-15

### Updated

- Scroll to bottom input when off screen

## 0.6.1 - 2019-07-15

### Updated
Expand Down
17 changes: 0 additions & 17 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
module.exports = {
// A list of paths to directories that Jest should use to search for files in
roots: ['<rootDir>/src'],

// A map from regular expressions to paths to transformers
transform: {
'^.+\\.tsx?$': 'ts-jest',
},

// The regexp pattern or array of patterns that Jest uses to detect test files
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',

// An array of file extensions your modules use
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],

// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: ['\\\\node_modules\\\\'],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
testPathIgnorePatterns: ['\\\\node_modules\\\\'],

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',

// Make calling deprecated APIs throw helpful error messages
errorOnDeprecated: true,

// A map from regular expressions to module names that allow to stub out resources with a single module
moduleNameMapper: {
'\\.(scss|jpg|png)$': '<rootDir>/node_modules/jest-css-modules',
'^-!svg-react-loader.*$': '<rootDir>/src/__mocks__/svgMock.tsx',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "termy-the-terminal",
"version": "0.6.1",
"version": "0.6.2",
"description": "Web-based terminal powered by React",
"main": "./dist/Terminal.js",
"license": "MIT",
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
import { Terminal } from '..';
import exampleFileSystem from '../data/exampleFileSystem';

beforeAll((): void => {
Element.prototype.scrollIntoView = jest.fn();
});

afterEach(cleanup);

describe('general', (): void => {
Expand Down
29 changes: 21 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export class Terminal extends Component<TerminalProps, TerminalState> {
fileSystem: this.props.fileSystem,
};

private inputWrapper: HTMLDivElement | null = null;

public componentDidUpdate(): void {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.inputWrapper!.scrollIntoView({ behavior: 'smooth' });
}

private handleChange = (event: ChangeEvent<HTMLInputElement>): void => {
this.setState({
inputValue: event.target.value,
Expand Down Expand Up @@ -77,14 +84,20 @@ export class Terminal extends Component<TerminalProps, TerminalState> {
return (
<div id="terminal-wrapper">
<History history={history} />
<Input
currentPath={currentPath}
handleChange={this.handleChange}
handleSubmit={this.handleSubmit}
inputValue={inputValue}
promptChar={promptChar}
readOnly={false}
/>
<div
ref={(el): void => {
this.inputWrapper = el;
}}
>
<Input
currentPath={currentPath}
handleChange={this.handleChange}
handleSubmit={this.handleSubmit}
inputValue={inputValue}
promptChar={promptChar}
readOnly={false}
/>
</div>
</div>
);
}
Expand Down
54 changes: 29 additions & 25 deletions src/styles/Terminal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,36 @@
overflow: auto;
padding: 0 1em;

#input-container {
padding: 1em 0;

form {
display: flex;

input {
background: none;
border: none;
color: map-get($themeDark, fontColor);
font-family: $fontFamily;
font-size: $fontSize;
outline: none;
-webkit-appearance: none;

flex-grow: 100;
margin: 0 10px;
}

#inputPromptChar {
color: map-get($themeDark, green);
}
}
}

#history-container {
& > ul > li > #input-container {
padding-bottom: 0;
}

#help-container ul > li {
margin: 5px 0;

Expand Down Expand Up @@ -56,29 +85,4 @@
}
}
}

#input-container {
padding-top: 1em;

form {
display: flex;

input {
background: none;
border: none;
color: map-get($themeDark, fontColor);
font-family: $fontFamily;
font-size: $fontSize;
outline: none;
-webkit-appearance: none;

flex-grow: 100;
margin: 0 10px;
}

#inputPromptChar {
color: map-get($themeDark, green);
}
}
}
}
35 changes: 20 additions & 15 deletions src/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta charset="utf-8" />
<title><%= htmlWebpackPlugin.options.title %></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://fonts.googleapis.com/css?family=Inconsolata"
rel="stylesheet"
/>
</head>
<body>
<style>
html, body {
height: 100%;
width: 100%;
}
#terminal-container {
height: 100%;
}
</style>
<div id="terminal-container">
</div>
<style>
html,
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
#terminal-container {
height: 100%;
}
</style>
<div id="terminal-container"></div>
</body>
</html>

0 comments on commit 457e995

Please sign in to comment.