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 support for CSS logical properties #174

Open
1 task done
roseg43 opened this issue Mar 10, 2023 · 0 comments
Open
1 task done

Fix support for CSS logical properties #174

roseg43 opened this issue Mar 10, 2023 · 0 comments

Comments

@roseg43
Copy link
Contributor

roseg43 commented Mar 10, 2023

Is your enhancement related to a problem? Please describe.

Currently, when using CSS logical properties, postcss creates two sets of rules, one for html[dir="ltr"] and one for html[dir="rtl"]. This would be fine, however, the native WordPress language_attributes() function only adds a dir attribute to html if the language direction is RTL.

I would like to see overrides.php in the theme include a filter on language_attributes to add dir="ltr" to the language attributes when is_rtl() is false.

Designs

An example of the function that adds this language attribute:

/**
 * Add the dir attribute to the body tag if it's LTR. WordPress doesn't do this by default, and postcss scopes CSS logical properties to the text direction.
 * This means that if the text direction is LTR, the CSS logical properties will not be applied.
 *
 * @see https://developer.wordpress.org/reference/functions/get_language_attributes/
 * @param string $output attribues to add to the body tag.
 *
 * @return string Updated attributes.
 */
function maybe_add_ltr_language_attribute( $output ) {
	// If the current language is LTR, add the dir attribute.
	if ( ! is_rtl() ) {
		$output .= ' dir="ltr"';
	}

	return $output;
}

Describe alternatives you've considered

An alternative could be modifying the default postcss config to handle logical properties in a way where RTL styles are scoped to html[dir="rtl"], while LTR styles are unscoped.

Code of Conduct

  • I agree to follow this project's Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant