Skip to content
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

Fix text direction for URL and email fields in block editor for RTL languages #68188

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const InsertFromURLPopover = ( {
<InputControl
__next40pxDefaultSize
label={ __( 'URL' ) }
type="url"
hideLabelFromVision
placeholder={ __( 'Paste or type URL' ) }
onChange={ onChange }
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/form/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const Edit = ( { attributes, setAttributes, clientId } ) => {
help={ __(
'The email address where form submissions will be sent. Separate multiple email addresses with a comma.'
) }
type="email"
/>
) }
</PanelBody>
Expand Down Expand Up @@ -159,6 +160,7 @@ const Edit = ( { attributes, setAttributes, clientId } ) => {
help={ __(
'The URL where the form should be submitted.'
) }
type="url"
/>
</InspectorControls>
) }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ function Controls( { attributes, setAttributes, setIsLabelFieldFocused } ) {
);
} }
autoComplete="off"
type="url"
/>
</ToolsPanelItem>

Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/navigation-submenu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ export default function NavigationSubmenuEdit( {
} }
label={ __( 'Link' ) }
autoComplete="off"
type="url"
/>
</ToolsPanelItem>

Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/rss/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default function RSSEdit( { attributes, setAttributes } ) {
<InputControl
__next40pxDefaultSize
label={ label }
type="url"
hideLabelFromVision
placeholder={ __( 'Enter URL here…' ) }
value={ feedURL }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ export const Input = styled.input< InputProps >`
&::-webkit-input-placeholder {
line-height: normal;
}
&[type='email'],
&[type='url'] {
/* rtl:ignore */
direction: ltr;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you reference the props directly, you should be able to output CSS conditionally. A possible approach would be something like this:

Details
diff --git a/packages/components/src/input-control/styles/input-control-styles.tsx b/packages/components/src/input-control/styles/input-control-styles.tsx
index 39eea8fdb0..ece01451db 100644
--- a/packages/components/src/input-control/styles/input-control-styles.tsx
+++ b/packages/components/src/input-control/styles/input-control-styles.tsx
@@ -4,7 +4,7 @@
 import type { SerializedStyles } from '@emotion/react';
 import { css } from '@emotion/react';
 import styled from '@emotion/styled';
-import type { CSSProperties, ReactNode } from 'react';
+import type { CSSProperties, ReactNode, HTMLInputTypeAttribute } from 'react';
 
 /**
  * Internal dependencies
@@ -141,6 +141,7 @@ type InputProps = {
        dragCursor?: CSSProperties[ 'cursor' ];
        paddingInlineStart?: CSSProperties[ 'paddingInlineStart' ];
        paddingInlineEnd?: CSSProperties[ 'paddingInlineEnd' ];
+       type?: HTMLInputTypeAttribute;
 };
 
 const disabledStyles = ( { disabled }: InputProps ) => {
@@ -262,6 +263,15 @@ const dragStyles = ( { isDragging, dragCursor }: InputProps ) => {
        `;
 };
 
+const directionStyles = ( { type }: InputProps ) => {
+       if ( type !== 'url' && type !== 'email' ) {
+               return '';
+       }
+       return css`
+               direction: ltr;
+       `;
+};
+
 // TODO: Resolve need to use &&& to increase specificity
 // https://github.com/WordPress/gutenberg/issues/18483
 
@@ -283,6 +293,7 @@ export const Input = styled.input< InputProps >`
                ${ fontSizeStyles }
                ${ sizeStyles }
                ${ customPaddings }
+               ${ directionStyles }
 
                &::-webkit-input-placeholder {
                        line-height: normal;

Copy link
Member

Choose a reason for hiding this comment

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

Any reason why we would prefer this over plain CSS selectors? I think in general we should use plain CSS instead of JS when possible, since it will be simpler both in terms of lines of code and runtime work. Another reason is that we are actually planning to move off of CSS-in-JS (#66806).

}
`;

Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/text-control/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@
padding-right: $grid-unit-15;
}
}

.components-text-control__input[type="email"],
.components-text-control__input[type="url"] {
/* rtl:ignore */
direction: ltr;
}
Loading