Skip to content

Commit

Permalink
fix: refined text input label truncation for single-word overflow (#1782
Browse files Browse the repository at this point in the history
)

Co-authored-by: Nitin Kumar <snitin315@gmail.com>
  • Loading branch information
harsh9975 and snitin315 authored Dec 1, 2023
1 parent 998e596 commit 2219e9a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-clocks-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@razorpay/blade": patch
---

fix: refined text input label truncation for single-word overflow
1 change: 1 addition & 0 deletions packages/blade/src/components/Form/FormLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const FormLabel = ({
size={isLabelLeftPositioned ? 'medium' : 'small'}
truncateAfterLines={2}
weight="bold"
wordBreak={isLabelLeftPositioned ? 'break-word' : undefined}
>
{children}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const StyledBaseText = styled.div.withConfig({
numberOfLines,
lineHeight,
textAlign,
wordBreak,
...props
}) => {
const styledPropsCSSObject = useStyledProps(props);
Expand All @@ -36,6 +37,7 @@ const StyledBaseText = styled.div.withConfig({
numberOfLines,
lineHeight,
textAlign,
wordBreak,
theme: props.theme,
}),
...styledPropsCSSObject,
Expand All @@ -56,6 +58,7 @@ export const BaseText = ({
textAlign,
children,
truncateAfterLines,
wordBreak,
className,
style,
accessibilityProps = {},
Expand All @@ -76,6 +79,7 @@ export const BaseText = ({
as={as}
textAlign={textAlign}
numberOfLines={truncateAfterLines}
wordBreak={wordBreak}
className={className}
style={style}
id={id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const getBaseTextStyles = ({
fontStyle = 'normal',
textDecorationLine = 'none',
numberOfLines,
wordBreak,
lineHeight = 100,
textAlign,
theme,
Expand All @@ -22,6 +23,7 @@ const getBaseTextStyles = ({
const themeFontWeight = theme.typography.fonts.weight[fontWeight];
const themeLineHeight = makeTypographySize(theme.typography.lineHeights[lineHeight]);
let truncateStyles: CSSObject = {};
let wordBreakStyles: CSSObject = {};
if (numberOfLines !== undefined) {
if (isReactNative()) {
truncateStyles = {};
Expand All @@ -35,6 +37,15 @@ const getBaseTextStyles = ({
};
}
}
if (wordBreak !== undefined) {
if (isReactNative()) {
wordBreakStyles = {};
} else {
wordBreakStyles = {
wordBreak,
};
}
}

return {
color: textColor,
Expand All @@ -51,6 +62,7 @@ const getBaseTextStyles = ({
margin: 0,
padding: 0,
...truncateStyles,
...wordBreakStyles,
};
};

Expand Down
2 changes: 2 additions & 0 deletions packages/blade/src/components/Typography/BaseText/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type BaseTextProps = {
fontStyle?: 'italic' | 'normal';
textDecorationLine?: 'line-through' | 'none' | 'underline';
lineHeight?: keyof Theme['typography']['lineHeights'];
wordBreak?: 'normal' | 'break-all' | 'keep-all' | 'break-word';
/**
* Web only
*/
Expand Down Expand Up @@ -87,6 +88,7 @@ export type StyledBaseTextProps = Pick<
| 'textAlign'
| 'numberOfLines'
| 'truncateAfterLines'
| 'wordBreak'
> & { theme: Theme };

export type BaseTextSizes = 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge';
3 changes: 3 additions & 0 deletions packages/blade/src/components/Typography/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type TextCommonProps = {
color?: BaseTextProps['color'];
textAlign?: BaseTextProps['textAlign'];
textDecorationLine?: BaseTextProps['textDecorationLine'];
wordBreak?: BaseTextProps['wordBreak'];
} & TestID &
StyledPropsBlade;

Expand Down Expand Up @@ -142,11 +143,13 @@ const _Text = <T extends { variant: TextVariant }>({
testID,
textAlign,
textDecorationLine,
wordBreak,
...styledProps
}: TextProps<T>): ReactElement => {
const props: Omit<BaseTextProps, 'children'> = {
as,
truncateAfterLines,
wordBreak,
...getTextProps({
variant,
type,
Expand Down

0 comments on commit 2219e9a

Please sign in to comment.