react-stripe-js icon indicating copy to clipboard operation
react-stripe-js copied to clipboard

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

Open metalmarker opened this issue 1 year ago • 4 comments

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:

  • Removing labels: floating (i.e., labels above the controls) results in correctly rendered controls
  • I'm using @stripe/stripe-js and stripe/react-stripe-js 2.4.0.

Environment

No response

Reproduction

No response

metalmarker avatar Feb 06 '24 19:02 metalmarker

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 }).

brendanm-stripe avatar Feb 13 '24 18:02 brendanm-stripe

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 avatar Feb 13 '24 18:02 metalmarker

@brendanm-stripe it looks this was resolved (I'm now on [email protected] and [email protected]). Great job!

metalmarker avatar Feb 22 '24 16:02 metalmarker

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.

tylersmith-stripe avatar Feb 26 '24 11:02 tylersmith-stripe

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.

stale[bot] avatar Apr 23 '24 02:04 stale[bot]