Skip to content

feat: Resize textarea using alt+up and alt+down arrow keys #1208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/profile/forms/Bio.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
constructor(props) {
super(props);

this.textareaRef = React.createRef();
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.handleClose = this.handleClose.bind(this);
this.handleOpen = this.handleOpen.bind(this);
this.handleResize = this.handleResize.bind(this);
}

handleChange(e) {
Expand All @@ -43,6 +45,25 @@
this.props.openHandler(this.props.formId);
}

handleResize(event) {

Check warning on line 48 in src/profile/forms/Bio.jsx

View check run for this annotation

Codecov / codecov/patch

src/profile/forms/Bio.jsx#L48

Added line #L48 was not covered by tests
if (event.altKey) {
const textarea = this.textareaRef.current;

Check warning on line 50 in src/profile/forms/Bio.jsx

View check run for this annotation

Codecov / codecov/patch

src/profile/forms/Bio.jsx#L50

Added line #L50 was not covered by tests
if (!textarea) {
return;

Check warning on line 52 in src/profile/forms/Bio.jsx

View check run for this annotation

Codecov / codecov/patch

src/profile/forms/Bio.jsx#L52

Added line #L52 was not covered by tests
}

const step = 10; // pixels to increase/decrease the height of the textarea

Check warning on line 55 in src/profile/forms/Bio.jsx

View check run for this annotation

Codecov / codecov/patch

src/profile/forms/Bio.jsx#L55

Added line #L55 was not covered by tests
if (event.key === 'ArrowUp') {
textarea.style.height = `${Math.max(30, textarea.offsetHeight - step)}px`;
event.preventDefault();

Check warning on line 58 in src/profile/forms/Bio.jsx

View check run for this annotation

Codecov / codecov/patch

src/profile/forms/Bio.jsx#L57-L58

Added lines #L57 - L58 were not covered by tests
}
if (event.key === 'ArrowDown') {
textarea.style.height = `${textarea.offsetHeight + step}px`;
event.preventDefault();

Check warning on line 62 in src/profile/forms/Bio.jsx

View check run for this annotation

Codecov / codecov/patch

src/profile/forms/Bio.jsx#L61-L62

Added lines #L61 - L62 were not covered by tests
}
}
}

render() {
const {
formId, bio, visibilityBio, editMode, saveState, error, intl,
Expand All @@ -68,7 +89,9 @@
id={formId}
name={formId}
value={bio}
ref={this.textareaRef}
onChange={this.handleChange}
onKeyDown={this.handleResize}
/>
{error !== null && (
<Form.Control.Feedback hasIcon={false}>
Expand Down