Skip to content
Merged
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
40 changes: 21 additions & 19 deletions src/components/TextInput/TextInputLabel/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import React, {PureComponent} from 'react';
import React, {useRef, useEffect} from 'react';
import {Animated} from 'react-native';
import styles from '../../../styles/styles';
import {propTypes, defaultProps} from './TextInputLabelPropTypes';
import CONST from '../../../CONST';

class TextInputLabel extends PureComponent {
Comment thread
kosmydel marked this conversation as resolved.
componentDidMount() {
if (!this.props.for) {
function TextInputLabel({for: inputId, label, labelTranslateY, labelScale}) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to rename for because it is a keyword.

const labelRef = useRef(null);

useEffect(() => {
if (!inputId || !labelRef.current) {
return;
}
this.label.setAttribute('for', this.props.for);
}
labelRef.current.setAttribute('for', inputId);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

render() {
return (
<Animated.Text
ref={(el) => (this.label = el)}
pointerEvents="none"
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
style={[styles.textInputLabel, styles.textInputLabelDesktop, styles.textInputLabelTransformation(this.props.labelTranslateY, 0, this.props.labelScale)]}
>
{this.props.label}
</Animated.Text>
);
}
return (
<Animated.Text
ref={labelRef}
pointerEvents="none"
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
style={[styles.textInputLabel, styles.textInputLabelDesktop, styles.textInputLabelTransformation(labelTranslateY, 0, labelScale)]}
>
{label}
</Animated.Text>
);
}

TextInputLabel.displayName = 'TextInputLabel';
TextInputLabel.propTypes = propTypes;
TextInputLabel.defaultProps = defaultProps;

export default TextInputLabel;
export default React.memo(TextInputLabel);