Skip to content

Commit f0d3411

Browse files
authored
Merge pull request #275 from argonism/fix-query-header-for-long-title
2 parents 2a89a68 + 305593d commit f0d3411

File tree

5 files changed

+76
-20
lines changed

5 files changed

+76
-20
lines changed
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
.QueryHeader {
22
position: relative;
3-
}
4-
5-
.QueryHeader-inputTitle {
6-
font-weight: bold;
7-
font-size: 24px;
8-
margin: 0;
9-
padding: 10px;
10-
outline: none;
11-
border: none;
12-
font-family: inherit;
13-
width: 100%;
14-
height: 28px;
3+
display: flex;
4+
flex-direction: row;
5+
justify-items: space-between;
156
}
167

178
.QueryHeader-selectDataSource {
18-
position: absolute !important;
19-
right: 10px;
20-
top: 6px;
9+
margin: auto 10px auto 20px;
2110
width: 240px;
2211
}

src/renderer/components/QueryHeader/QueryHeader.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Select from "react-select";
33
import { selectStyles } from "../Select";
44
import { QueryType } from "../../../lib/Database/Query";
55
import { DataSourceType } from "../../pages/DataSource/DataSourceStore";
6+
import QueryHeaderTitle from "../QueryHeaderTitle";
67

78
type Props = {
89
readonly query: QueryType;
@@ -12,10 +13,6 @@ type Props = {
1213
};
1314

1415
const QueryHeader: React.FC<Props> = ({ query, dataSources, onChangeTitle, onChangeDataSource }) => {
15-
const handleChangeTitle = (e: React.ChangeEvent<HTMLInputElement>): void => {
16-
onChangeTitle(e.target.value);
17-
};
18-
1916
const handleChangeDataSource = React.useCallback(
2017
(e: any): void => {
2118
onChangeDataSource(e.value);
@@ -30,7 +27,7 @@ const QueryHeader: React.FC<Props> = ({ query, dataSources, onChangeTitle, onCha
3027

3128
return (
3229
<div className="QueryHeader">
33-
<input className="QueryHeader-inputTitle" type="text" value={query.title} onChange={handleChangeTitle} />
30+
<QueryHeaderTitle title={query.title} onChangeTitle={onChangeTitle} />
3431
<Select
3532
className="QueryHeader-selectDataSource"
3633
value={currentOption}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.QueryHeaderTitle {
2+
position: relative;
3+
width: 100%;
4+
}
5+
6+
.QueryHeaderTitle-textarea {
7+
position: absolute;
8+
top: 0;
9+
left: 0;
10+
11+
/* in order to center textarea.
12+
There might be more proper way to do this. */
13+
margin-top: 2px;
14+
15+
font-weight: bold;
16+
font-size: 24px;
17+
padding-left: 10px;
18+
outline: none;
19+
border: none;
20+
font-family: inherit;
21+
width: 100%;
22+
23+
resize: none;
24+
word-break: break-all;
25+
}
26+
27+
.QueryHeaderTitle-textarea:focus {
28+
border: 1px solid #ccc;
29+
border-width: 0 1px 1px 0;
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from "react";
2+
3+
type Props = {
4+
readonly title: string;
5+
readonly onChangeTitle: (title: string) => void;
6+
};
7+
8+
const QueryHeaderTitle: React.FC<Props> = ({ title, onChangeTitle }) => {
9+
const handleTextareaHeight = (element: HTMLTextAreaElement): void => {
10+
element.style.height = "";
11+
element.style.height = element.scrollHeight + "px";
12+
};
13+
14+
const handleTextareaBlur = (e: React.FocusEvent<HTMLTextAreaElement>): void => {
15+
e.target.style.height = "";
16+
};
17+
18+
const handleChangeTitle = (e: React.ChangeEvent<HTMLTextAreaElement>): void => {
19+
onChangeTitle(e.target.value);
20+
handleTextareaHeight(e.target);
21+
};
22+
23+
return (
24+
<div className="QueryHeaderTitle">
25+
<textarea
26+
className="QueryHeaderTitle-textarea"
27+
value={title}
28+
onFocus={(e) => handleTextareaHeight(e.target)}
29+
onChange={handleChangeTitle}
30+
onBlur={handleTextareaBlur}
31+
rows={1}
32+
/>
33+
</div>
34+
);
35+
};
36+
37+
export default QueryHeaderTitle;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./QueryHeaderTitle.css";
2+
import QueryHeaderTitle from "./QueryHeaderTitle";
3+
export default QueryHeaderTitle;

0 commit comments

Comments
 (0)