-
Notifications
You must be signed in to change notification settings - Fork 109
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
[Order - Shipping - Custom Amounts - Cash] Highlight amount when focused #14030
Conversation
📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a reasonable compromise, to avoid a significant refactor!
A couple notes:
- There are a couple UI tests that need to be updated to handle the changes here, see also my comment below.
- Did you consider using something like a border around the text field to indicate that it has focus? That has the advantage of working even if there is an amount already entered. This approach works to highlight the empty field, but there's no change if it has a value. (I think it's fine to leave it as-is, just mentioning it as an alternate approach.)
@@ -17,7 +17,9 @@ struct FormattableAmountTextField: View { | |||
// Hidden input text field | |||
TextField("", text: $viewModel.textFieldAmountText) | |||
.onChange(of: viewModel.textFieldAmountText, perform: viewModel.updateAmount) | |||
.focused() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you intentionally removing the auto-focus this field gets from the .focused()
modifier?
If so, we'll need to update the UI tests to tap on this field so it gets focused. (Right now, the tests that include this field are failing because the field doesn't get focus so the keyboard doesn't appear to enter the amount.)
Alternately, we could keep the .focused()
modifier and just add the .onChange(of: focusAmountInput)
modifier on top of it. That way the field still gets auto-focus but the placeholder text is also highlighted.
Thanks for your input @rachelmcr ! That makes sense. I tried with the border and this is how it looks: @joe-keenan We can use your input here :) We're trying to make it visible to the user when the formattable amount text field, a component we use in several parts of the app is focused. Since this is a custom component we don't show the cursor, which makes it difficult to communicate to the user that it's being focused and they can edit it (see original issue) What approach do you think it's more convenient and consistent?
|
That border looks nice! What if you add the border modifier after the |
|
Hey all, thanks for the ping. I included the cursor in all my designs for this text field style. It’s the most commonly used element of all text fields to indicate not just that the field is focused, but also where the user should expect to see their typing appear. I’ve been meaning to raise it in my design dusting posts soon. Are you really sure we can’t show it? I think it breaks the UX not to have it. I also noticed that in your first video, for shipping, the cursor is visible. ichqhxDjbmZZmvJaJkGhkj-fi-698_29716 (Link to Figma designs for custom amounts) As for focusing the field, the border below the text area is supposed to be the bottom of the field, so my first thought is to try making that border bold and purple. This is probably a good idea even if we show the cursor. |
Version |
Version |
@rachelmcr Could you please check the implementation again? For now I think showing the border is a good idea, and I added this issue to add the cursor eventually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I tested the three places where this field is used, and it worked as expected everywhere:
- Custom amount
- Shipping amount
- Cash payment amount
Thanks for opening an issue about the cursor, too; I think this behavior is a good compromise for now but it's good to keep track of that improvement.
@@ -28,6 +28,8 @@ struct FormattableAmountTextField: View { | |||
.minimumScaleFactor(0.1) | |||
.lineLimit(1) | |||
.frame(maxWidth: .infinity, alignment: .leading) | |||
.padding(5) | |||
.roundedBorder(cornerRadius: 8, lineColor: focusAmountInput ? Color(.wooCommercePurple(.shade60)) : .clear, lineWidth: 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works great! Just to offer an alternate approach, I find that our if
modifier helps clarify the intent when reading this (clarifying that we add a border if the field has focus):
.if(focusAmountInput, transform: { field in
field.roundedBorder(cornerRadius: 8, lineColor: Color(.wooCommercePurple(.shade60)), lineWidth: 1)
})
But no need to make any changes; just mentioning it for the potential readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review and the suggestion @rachelmcr ! Indeed, it makes it more readable. I added it in the last commit
Closes: #13956
Description
With this PR we highlight the amount field when is focused.
The reason why this issue happens is because the
FormattableAmountTextField
is composed of a hiddenTextField
to gather the input data and aText
to show the formatted amount. Since the text field is hidden, the editing cursor is also invisible, making it a bit confusing to the user who doesn't know for sure whether they are editing it or not.With this PR we highlight the Text when the hidden Text Field is focused. That shows the user that the amount text field is focused and they can enter the data. Ideally, we would show the cursor, but that implies a refactor into this class that might not be worth the effort. We can revisit this decision depending on user feedback.
Steps to reproduce
Testing information
This component is also used in Custom Amounts and Cash Payments, we have to cover also that. (see videos)
Screenshots
Shipping
ScreenRecording_09-24-2024.17-01-28_1.MP4
Custom Amounts
ScreenRecording_09-24-2024.17-02-06_1.MP4
Cash Payments
ScreenRecording_09-24-2024.17-03-47_1.MP4
RELEASE-NOTES.txt
if necessary.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: