stripe / react-stripe-js

React components for Stripe.js and Stripe Elements
https://stripe.com/docs/stripe-js/react
MIT License
1.7k stars 259 forks source link

[BUG]: Elements controls with floating labels are rendered incorrectly #470

Closed metalmarker closed 2 months ago

metalmarker commented 5 months ago

What happened?

I'm using <Elements> in my React app and interested in using floating labels . The problem is that the controls are rendered incorrectly, as can be seen below.

I'm passing the following appearance object inside the options object passed to <Elements>:

 appearance = {
   theme: 'stripe',
   labels: 'floating'
 }

The result is this:

Screenshot 2024-02-06 at 10 29 38 AM

When I look on the CSS associated with the of each field, it looks like there's a calculation errors in the --c-labelFloatingTransform, --c-labelRestingTransform and --c-inputFloatingPaddingTop variables as they include a NaN. Once I manually override the NaNs variables, the controls render correctly.

Screenshot 2024-02-06 at 10 29 01 AM

_

Additional information:

Environment

No response

Reproduction

No response

brendanm-stripe commented 4 months ago

Hey there, thanks for the report on this. We've been investigating. Can you confirm that your integration has the payment element inside a hidden element that you then make visible?

Assuming thats the case, we're working on a general fix but a workaround you might be able to use in the meantime is forcing an Appearance API recalculation after the container is visible using elements.update({ appearance: currentAppearance }).

metalmarker commented 4 months ago

Can you confirm that your integration has the payment element inside a hidden element that you then make visible?

Confirmed. That was one fast root cause analysis! I'm hiding the contents of the entire page (which includes the PaymentElement) until after it sends the onReady event.

I'll try out the suggested workaround. Thank you.

metalmarker commented 4 months ago

@brendanm-stripe it looks this was resolved (I'm now on stripe-js@3.0.5 and react-stripe-js@2.4.0). Great job!

tylersmith-stripe commented 4 months ago

Yes, to follow-up here, we've fixed this issue for the Payment Element!

We're continuing to apply this fix for Link Authentication Element and Address Element as a fast-follow.

We'll update and close out this ticket when those are fixed as well.

stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.