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

Discrepancy in the behavior of text-transform: capitalize between React Native and React Native Web. #2715

Open
1 task done
Mak-3 opened this issue Sep 22, 2024 · 3 comments
Labels

Comments

@Mak-3
Copy link

Mak-3 commented Sep 22, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

The current implementation of text-transform: capitalize in react-native-web does not match the behavior found in React Native. In React Native, this transformation converts all characters in a word to lowercase except for the first letter, which is capitalized. However, in react-native-web, the transformation only capitalizes the first letter of each word while leaving the remaining letters unchanged.

Expected behavior

Input: "hello WORLD from ReAcT nAtIvE"
Expected Output: "Hello World From React Native"
Current Output: "Hello WORLD From ReAcT nAtIvE"

Steps to reproduce

  1. Set Up Environment:

    • Create a new React Native project using Expo or React Native CLI.
    • Set up a React Native Web environment (e.g., using Expo for web or a separate React project with react-native-web).
  2. Create a Component:

    • In both the React Native and React Native Web projects, create a simple component that uses the Text component from both libraries.
  3. Add Text with Capitalization:

    • Use the following example text in both projects:

      <Text style={{ textTransform: 'capitalize' }}>
        hello WORLD from ReAcT nAtIvE
      </Text>
  4. Run Both Environments:

    • For React Native, run the app on a mobile simulator or device.
    • For React Native Web, run the app in a web browser.
  5. Observe the Output:

    • Check the output in both environments:
      • React Native: The expected output should be "Hello World From React Native".
      • React Native Web: The output will likely be "Hello WORLD From ReAcT nAtIvE".
  6. Compare Results:

    • Note the difference in behavior between the two platforms, highlighting the mismatch in capitalization.

Expected Result

  • React Native should properly capitalize the first letter of each word while converting the rest to lowercase.
  • React Native Web should only capitalize the first letter of each word without altering the case of the remaining letters.

Test case

https://codesandbox.io/s/sad-morning-79dhqp?file=/src/App.js

Additional comments

No response

@Mak-3 Mak-3 added the bug label Sep 22, 2024
Mak-3 pushed a commit to Mak-3/react-native-web that referenced this issue Sep 22, 2024
@necolas
Copy link
Owner

necolas commented Sep 23, 2024

You should open an issue against React Native so that it matches the browser behavior

@Mak-3
Copy link
Author

Mak-3 commented Sep 23, 2024

React Native uses the NSString class from Objective-C, where this behavior is expected and intentional.
Reference: capitalized

@necolas
Copy link
Owner

necolas commented Sep 23, 2024

React Native implements the CSS property, so it should match how the web works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants