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

feat: input and label components #70

Merged
merged 29 commits into from
Jan 16, 2024
Merged

feat: input and label components #70

merged 29 commits into from
Jan 16, 2024

Conversation

ionutanin
Copy link
Contributor

Closes #50

Changes proposed in this pull request

  • add reusable input and label component as per graphic design
  • add input unit tests

@ionutanin ionutanin added the area: popup Improvements or additions to extension popup label Dec 31, 2023
@raducristianpopa
Copy link
Member

raducristianpopa commented Dec 31, 2023

Extension builds preview

Name Link
Latest commit 7a0683f
Latest job logs Run #7545457118
BadgeDownload
BadgeDownload
BadgeDownload
BadgeDownload

Base automatically changed from rp--button-component to main January 8, 2024 05:16
src/components/label.tsx Outdated Show resolved Hide resolved
src/components/label.tsx Outdated Show resolved Hide resolved
src/components/input.tsx Outdated Show resolved Hide resolved
Comment on lines 21 to 23
loading: {
true: 'text-transparent',
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the text needs to be transparent in the loading state?

Copy link
Contributor Author

@ionutanin ionutanin Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover - in this case we will handle the loading with disabled state which behaves the same

src/components/input.tsx Outdated Show resolved Hide resolved
type?: 'text' | 'password' | 'email' | 'number'
}

export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we pass an error message we need to:

  • render the error message below the input
  • add the aria-invalid and aria-describedby attributes to the input

Additionally we can use the label component directly, by adding a label prop:

<Input label="Amount" {...restOfProps} />

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we must use it separately because there is a situation when we have also a link besides the actualy label (as per graphic)
e.g. Label link

) {
return (
<div className="relative">
{icon && <div className="absolute left-4 top-4">{icon}</div>}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we satisfied with the absolute positioning for the icon or should we inline it with the input?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine for now, I don't see yet an advantage of using it inline 🤔

Comment on lines 7 to 12
it('should render an input with the `aria-label` attribute', () => {
const { queryByLabelText } = render(<Input aria-label="test input" />)

expect(queryByLabelText('test input')).toBeInTheDocument()
expect(queryByLabelText('test input')).toHaveAttribute('aria-label', 'test input')
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to the aria-label attribute for the input, since the label will be available in the DOM.

src/components/__tests__/input.test.tsx Outdated Show resolved Hide resolved
Comment on lines 46 to 51
it('should have the `border-error` class when the `error` variant is passed', () => {
const { queryByLabelText } = render(<Input aria-label="test input" error />)

expect(queryByLabelText('test input')).toBeInTheDocument()
expect(queryByLabelText('test input')).toHaveClass('border-error')
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also check if the error message is present in the DOM and if the input has the aria-invalid and aria-labeledby attributes.

ionutanin and others added 2 commits January 8, 2024 14:22
Co-authored-by: Radu-Cristian Popa <[email protected]>
Co-authored-by: Radu-Cristian Popa <[email protected]>
@github-actions github-actions bot added the area: ci Improvements or additions to repository workflows label Jan 8, 2024
ionutanin and others added 7 commits January 8, 2024 14:23
@github-actions github-actions bot removed the area: ci Improvements or additions to repository workflows label Jan 10, 2024
className={cn(inputVariants({ disabled }), icon && 'pl-12', className)}
disabled={disabled ?? false}
aria-disabled={disabled ?? false}
aria-invalid={!!errorMessage || undefined}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that !!errorMessage should be sufficient.

Comment on lines 54 to 56
<div className="absolute top-full left-0 right-0 text-error text-sm px-2">
{errorMessage}
</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not set absolute position to the error message. A simple p tag should work.

aria-describedby={errorMessage}
{...props}
/>
{errorMessage && <p>{errorMessage}</p>}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the absolute position styles needed to be removed. Let's keep the other ones.

@ionutanin ionutanin linked an issue Jan 16, 2024 that may be closed by this pull request
@ionutanin ionutanin self-assigned this Jan 16, 2024
@ionutanin ionutanin merged commit eebfa3f into main Jan 16, 2024
9 checks passed
@ionutanin ionutanin deleted the rp--input-component branch January 16, 2024 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: popup Improvements or additions to extension popup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add label component Add input component
2 participants