Skip to content

Conversation

@JayadityaGit
Copy link
Contributor

@JayadityaGit JayadityaGit commented Oct 3, 2025

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work is based on designs, which are linked or shown either in the Jira ticket or the description below.
  • My work includes tests or is validated by existing tests.

Summary

This PR addresses the issue of no visual feedback when a user clicks the search button with an empty search term. To improve user experience, the following changes have been implemented:

  • When the search button is clicked with an empty search field, the placeholder text of the search input darkens for 5 seconds.
  • The search input field is also focused in this scenario.

These changes provide a clear visual cue to the user that the search term is missing.

Screenshots

simple.1.mp4

Related Issue

https://openmrs.atlassian.net/browse/O3-5068

Other

None.

@JayadityaGit
Copy link
Contributor Author

JayadityaGit commented Oct 3, 2025

@ibacher Could you please review this PR? If you’re happy with the changes, I’d appreciate it if you could add the hacktoberfest-accepted label to this PR, as I’m participating in Hacktoberfest.

Thanks a lot for your support! I’m also open to making any further refinements you suggest.

@JayadityaGit
Copy link
Contributor Author

@denniskigen Why does it feel like only my PRs are getting hit by these flaky tests? 😭

@JayadityaGit
Copy link
Contributor Author

Awesome! 🎉 the E2E tests are passing now.

@denniskigen denniskigen requested a review from ibacher October 7, 2025 11:21
<Search
autoFocus
className={styles.patientSearchInput}
className={`${styles.patientSearchInput} ${isInputClicked ? styles.darkPlaceholder : ''}`}
Copy link
Member

Choose a reason for hiding this comment

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

We generally use the classnames library for stuff like this:

Suggested change
className={`${styles.patientSearchInput} ${isInputClicked ? styles.darkPlaceholder : ''}`}
className={classNames('styles.patientSearchInput', { [styles.darkPlaceholder]: isInputClicked })}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks !

const [searchTerm, setSearchTerm] = useState(initialSearchTerm);
const [isInputClicked, setIsInputClicked] = useState(false);
const responsiveSize = isCompact ? 'sm' : 'lg';
const inputRef = useRef(null);
Copy link
Member

Choose a reason for hiding this comment

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

So modifying the ref here makes this (a component that exposes a ref a breaking change. This is because the component-user supplied ref will now not point to the DOM element.

To fix this, we need to add the following:

useImperativeHandle(ref, () => inputRef.current!)

This allows us to use a component-internal ref and properly expose it to consumers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks !

if (isInputClicked) {
const timeout = setTimeout(() => {
setIsInputClicked(false);
}, 5000);
Copy link
Member

Choose a reason for hiding this comment

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

5 seconds feels quite long for this interaction. I'd maybe make it 3 seconds tops. The idea is to catch the users eye.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks will make it 3 sec.


const handleSubmit = useCallback(
(event: React.FormEvent<HTMLFormElement>) => {
(event) => {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why this removes the type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks ! will get it back.

Comment on lines 36 to 38
} else {
setIsInputClicked(true);
inputRef.current.focus();
Copy link
Member

Choose a reason for hiding this comment

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

Again, from my comments, I suggested only triggering this on a click on the button. Putting this is the submit handler also triggers when the user hits enter and that's exactly the thing we wanted to avoid.

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 understand your point, but I don’t see a strong reason to exclude the Enter key. The user already needs to click the search icon with their mouse to access the search bar. Once it’s active, pressing Enter feels like a natural alternative way to trigger the advanced search results. Moreover, if the user clicks anywhere outside the search bar, it disappears—so the Enter action wouldn’t interfere with other interactions.

Copy link
Contributor Author

@JayadityaGit JayadityaGit Oct 8, 2025

Choose a reason for hiding this comment

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

once the user has already clicked the search icon and started typing, it’s more convenient for them to simply press Enter rather than reaching for the mouse again(during that timeframe). It feels like a natural flow from a usability perspective.

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 disagree that it's a natural flow. The question is does the user need the box to be highlighted if they press enter without typing anything? That feels like an accidental keypress rather than an operation the user was trying to perform, so it's better if the system does nothing. OTOH, the user clicking the search button seems like a non-accidental action, so it makes more sense to call attention to why nothing happened.

}

.darkPlaceholder ::placeholder {
color: #393939 !important;
Copy link
Member

Choose a reason for hiding this comment

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

Not sure where this came from. Use $text-02 or import the Carbon theme and use theme.$text-primary so this aligns with our standard colors. We generally don't invent colors if possible.

Copy link
Member

Choose a reason for hiding this comment

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

Also, instead of just changing the color here, maybe we use a 1s animation to fade between the current color and the new color...

E.g.,

.darkPlaceholder ::placeholder {
  animation: fade-dark 1s;
}

@keyframes fade-dark {
   0% {}
   100% { color: $text-02 !important; }
}

Something along those lines...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure !

@JayadityaGit
Copy link
Contributor Author

If removing the Enter key is truly necessary, I’ll be happy to include that change in the next commit.

@JayadityaGit JayadityaGit requested a review from ibacher October 8, 2025 12:15
@JayadityaGit
Copy link
Contributor Author

Thanks for the thoughtful review @ibacher !

If it’s not too much trouble, could you please add the hacktoberfest-accepted label to this PR? I’m participating in Hacktoberfest and would really appreciate it.

Thank you so much for your time and support! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants