diff --git a/webapp/channels/src/components/__snapshots__/autosize_textarea.test.tsx.snap b/webapp/channels/src/components/__snapshots__/autosize_textarea.test.tsx.snap
index 3bda56384f..5b4e3eae43 100644
--- a/webapp/channels/src/components/__snapshots__/autosize_textarea.test.tsx.snap
+++ b/webapp/channels/src/components/__snapshots__/autosize_textarea.test.tsx.snap
@@ -35,24 +35,15 @@ exports[`components/AutosizeTextarea should match snapshot, init 1`] = `
}
}
>
-
-
-
= maxWidth) {
+ if (width >= maxWidth) {
setShowFormattingSpacer(true);
} else {
setShowFormattingSpacer(false);
@@ -377,22 +372,6 @@ const AdvanceTextEditor = ({
}
}, [handleWidthChange, message]);
- useEffect(() => {
- if (!input) {
- return;
- }
-
- let padding = 16;
- if (showFormattingBar) {
- padding += 32;
- }
- if (renderScrollbar) {
- padding += 8;
- }
-
- input.style.paddingRight = `${padding}px`;
- }, [showFormattingBar, renderScrollbar, input]);
-
const formattingBar = (
{
private height: number;
private textarea?: HTMLTextAreaElement;
- private referenceRef: React.RefObject
;
- private measuringRef: React.RefObject;
+ private referenceRef: React.RefObject;
constructor(props: Props) {
super(props);
@@ -30,7 +30,6 @@ export class AutosizeTextarea extends React.PureComponent {
this.height = 0;
this.referenceRef = React.createRef();
- this.measuringRef = React.createRef();
}
componentDidMount() {
@@ -41,7 +40,6 @@ export class AutosizeTextarea extends React.PureComponent {
componentDidUpdate() {
this.recalculateHeight();
this.recalculateWidth();
- this.recalculatePadding();
}
private recalculateHeight = () => {
@@ -64,25 +62,12 @@ export class AutosizeTextarea extends React.PureComponent {
}
};
- private recalculatePadding = () => {
- if (!this.referenceRef.current || !this.textarea) {
- return;
- }
-
- const textarea = this.textarea;
- const {paddingRight} = getComputedStyle(textarea);
-
- if (paddingRight && paddingRight !== this.referenceRef.current.style.paddingRight) {
- this.referenceRef.current.style.paddingRight = paddingRight;
- }
- };
-
private recalculateWidth = () => {
- if (!this.measuringRef) {
+ if (!this.referenceRef) {
return;
}
- const width = this.measuringRef.current?.offsetWidth || -1;
+ const width = this.referenceRef.current?.offsetWidth || -1;
if (width >= 0) {
window.requestAnimationFrame(() => {
this.props.onWidthChange?.(width);
@@ -154,6 +139,18 @@ export class AutosizeTextarea extends React.PureComponent {
);
}
+ let referenceValue = value || defaultValue;
+ if (referenceValue?.endsWith('\n')) {
+ // In a div, the browser doesn't always count characters at the end of a line when measuring the dimensions
+ // of text. In the spec, they refer to those characters as "hanging". No matter what value we set for the
+ // `white-space` of a div, a single newline at the end of the div will always hang.
+ //
+ // The textarea doesn't have that behaviour, so we need to trick the reference div into measuring that
+ // newline, and it seems like the best way to do that is by adding a second newline because only the final
+ // one hangs.
+ referenceValue += '\n';
+ }
+
return (
{textareaPlaceholder}
@@ -173,23 +170,16 @@ export class AutosizeTextarea extends React.PureComponent
{
defaultValue={defaultValue}
/>
-
-
- {value || defaultValue}
+ {referenceValue}
@@ -199,9 +189,8 @@ export class AutosizeTextarea extends React.PureComponent {
const styles: { [Key: string]: CSSProperties} = {
container: {height: 0, overflow: 'hidden'},
- reference: {height: 'auto', width: '100%'},
+ reference: {display: 'inline-block', height: 'auto', width: 'auto'},
placeholder: {overflow: 'hidden', textOverflow: 'ellipsis', opacity: 0.5, pointerEvents: 'none', position: 'absolute', whiteSpace: 'nowrap', background: 'none', borderColor: 'transparent'},
- measuring: {width: 'auto', display: 'inline-block'},
};
const forwarded = React.forwardRef((props, ref) => (
diff --git a/webapp/channels/src/components/textbox/textbox.tsx b/webapp/channels/src/components/textbox/textbox.tsx
index d455bd41d0..a148328f34 100644
--- a/webapp/channels/src/components/textbox/textbox.tsx
+++ b/webapp/channels/src/components/textbox/textbox.tsx
@@ -263,10 +263,7 @@ export default class Textbox extends React.PureComponent {
};
render() {
- let preview = null;
-
let textboxClassName = 'form-control custom-textarea';
- let textWrapperClass = 'textarea-wrapper';
if (this.props.emojiEnabled) {
textboxClassName += ' custom-textarea--emoji-picker';
}
@@ -276,25 +273,28 @@ export default class Textbox extends React.PureComponent {
if (this.props.hasLabels) {
textboxClassName += ' textarea--has-labels';
}
- if (this.props.preview) {
- textboxClassName += ' custom-textarea--preview';
- textWrapperClass += ' textarea-wrapper--preview';
- preview = (
+ if (this.props.preview) {
+ return (
);
}
@@ -302,7 +302,7 @@ export default class Textbox extends React.PureComponent {
return (
{
openWhenEmpty={this.props.openWhenEmpty}
alignWithTextbox={this.props.alignWithTextbox}
/>
- {preview}
);
}
diff --git a/webapp/channels/src/sass/components/_post.scss b/webapp/channels/src/sass/components/_post.scss
index 89bd04875a..3836424846 100644
--- a/webapp/channels/src/sass/components/_post.scss
+++ b/webapp/channels/src/sass/components/_post.scss
@@ -13,7 +13,7 @@
line-height: 20px;
resize: none;
transition: none;
- white-space: pre-wrap;
+ white-space: break-spaces;
word-wrap: break-word;
&:focus {
@@ -31,14 +31,6 @@
position: relative;
min-height: 37px;
- &.textarea-wrapper--preview {
- > div {
- &:first-child {
- display: none;
- }
- }
- }
-
.textbox-preview-area {
ul {
white-space: normal;
@@ -384,14 +376,6 @@
scrollbar-width: thin;
transition: height 150ms ease-in-out;
- &:not(.custom-textarea--emoji-picker) {
- padding-right: 40px;
- }
-
- &.custom-textarea--emoji-picker {
- padding-right: 90px;
- }
-
&.textbox-preview-area {
overflow-y: auto;
}
@@ -412,14 +396,6 @@
overflow: auto;
-webkit-overflow-scrolling: touch;
-ms-overflow-style: auto;
-
- &:not(.custom-textarea--emoji-picker) {
- padding-right: 50px;
- }
-
- &.custom-textarea--emoji-picker {
- padding-right: 90px;
- }
}
}
@@ -696,7 +672,7 @@
.custom-textarea {
max-height: calc(50vh - 40px);
- padding: 13px 0 12px 16px;
+ padding: 13px 16px 12px 16px;
background-color: var(--center-channel-bg);
&.custom-textarea--emoji-picker {
diff --git a/webapp/channels/src/sass/responsive/_mobile.scss b/webapp/channels/src/sass/responsive/_mobile.scss
index 3ab1e421f3..e56b71a287 100644
--- a/webapp/channels/src/sass/responsive/_mobile.scss
+++ b/webapp/channels/src/sass/responsive/_mobile.scss
@@ -757,13 +757,6 @@
display: block;
}
- .custom-textarea {
- &.custom-textarea--emoji-picker {
- max-height: 162px;
- padding-right: 135px;
- }
- }
-
textarea {
.app-content & {
border-right: none;