1 Answers

Problem

You have defined the NewUrlForm component inside the Home component. That is causing the focus issue.

Solution

  1. Move the NewUrlForm as a separate component to the Home component level.
function NewUrlForm({ onSubmit, originalUrl, inputHandler }) {
  return (
    <>
      <form onSubmit={onSubmit}>
        <label
          className="block mb-5 text-lg font-medium text-gray-900 dark:text-gray-600"
          htmlFor="original-url"
        >
          URL
        </label>
        <input
          value={originalUrl}
          onChange={inputHandler}
          className="block w-full px-3 py-1.5 text-base font-normal text-gray-700 bg-white bg-clip-padding border border-solid border-gray-300 rounded transition ease-in-out m-0 focus:text-gray-700 focus:bg-white focus:border-blue-600 focus:outline-none
            "
          id="original-url"
          type="text"
          placeholder="https://example.com"
          required
        />

        <button
          type="submit"
          className="trasition duration-200 text-white bg-blue-700 hover:bg-blue-800 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mt-6 mb-2 w-full"
        >
          Create
        </button>
      </form>
    </>
  );
}
  1. Pass the required props to NewUrlForm component.
<NewUrlForm
  onSubmit={onSubmit}
  originalUrl={originalUrl}
  inputHandler={inputHandler}
/>
Related