Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -28,6 +28,16 @@ describe('isValidPartialFiatAmountInput', () => {
});

describe('PerpsFiatHeroAmountInput', () => {
it('renders symbol and input for the given value', () => {
render(<PerpsFiatHeroAmountInput value="2.707414" onChange={jest.fn()} />);
expect(
screen.getByTestId('perps-fiat-hero-amount-symbol'),
).toBeInTheDocument();
expect(screen.getByTestId('perps-fiat-hero-amount-input')).toHaveValue(
'2.707414',
);
});

it('renders symbol and forwards input changes', () => {
const onChange = jest.fn();
render(<PerpsFiatHeroAmountInput value="" onChange={onChange} />);
Expand All @@ -46,9 +56,8 @@ describe('PerpsFiatHeroAmountInput', () => {
<PerpsFiatHeroAmountInput value="1" onChange={jest.fn()} isLoading />,
);

expect(
screen.getByTestId('perps-fiat-hero-amount-skeleton'),
).toBeInTheDocument();
const skeleton = screen.getByTestId('perps-fiat-hero-amount-skeleton');
expect(skeleton).toBeInTheDocument();
expect(
screen.queryByTestId('perps-fiat-hero-amount-input'),
).not.toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const PerpsFiatHeroAmountSkeleton: React.FC = () => (
flexDirection={BoxFlexDirection.Row}
justifyContent={BoxJustifyContent.Center}
alignItems={BoxAlignItems.Center}
className="w-full"
style={{ minHeight: '70px' }}
data-testid="perps-fiat-hero-amount-skeleton"
>
Expand Down Expand Up @@ -134,6 +135,7 @@ export const PerpsFiatHeroAmountInput: React.FC<PerpsFiatHeroAmountInputProps> =
flexDirection={BoxFlexDirection.Row}
justifyContent={BoxJustifyContent.Center}
alignItems={BoxAlignItems.Center}
className="w-full"
Comment thread
abretonc7s marked this conversation as resolved.
style={{ minHeight: '70px' }}
>
<Text
Expand All @@ -145,27 +147,56 @@ export const PerpsFiatHeroAmountInput: React.FC<PerpsFiatHeroAmountInputProps> =
>
{fiatSymbol}
</Text>
<input
data-testid="perps-fiat-hero-amount-input"
type="text"
inputMode="decimal"
value={value}
onChange={handleChange}
disabled={disabled}
className={twMerge(
textColor,
'border-none bg-transparent text-left outline-none',
disabled ? 'cursor-default' : 'cursor-text',
)}
style={
{
{/*
* Absolute-overlay pattern: the hidden clone (white-space:pre) drives
* the outer span's width to the exact rendered text width, while the
* absolutely-positioned input fills that same box. Absolute children
* are out-of-flow so they don't affect the parent's max-content width,
* avoiding the circular-dependency that broke the inline-grid approach.
* Works in Chrome, Firefox, and Safari (unlike field-sizing:content).
*/}
<span
style={{
position: 'relative',
width: 'max-content',
minWidth: '1ch',
}}
>
<span
aria-hidden="true"
style={{
display: 'block',
visibility: 'hidden',
whiteSpace: 'pre',
fontSize,
lineHeight,
fontWeight: 500,
minWidth: '1ch',
}}
>
{value || '0'}
</span>
<input
data-testid="perps-fiat-hero-amount-input"
type="text"
inputMode="decimal"
value={value}
onChange={handleChange}
disabled={disabled}
className={twMerge(
textColor,
'border-none bg-transparent text-left outline-none',
disabled ? 'cursor-default' : 'cursor-text',
)}
style={{
position: 'absolute',
inset: 0,
fontSize,
lineHeight,
fontWeight: 500,
width: `${Math.max(1, amountLength)}ch`,
} as React.CSSProperties
}
/>
}}
/>
</span>
</Box>
);
},
Expand Down
Loading