dataesr/react-dsfr

SearchBar button onClick causes my page to refresh

Closed this issue · 3 comments

Behaviour expected: I don't want my page to refresh when click the search button.
Current behaviour: page is refreshing.

Fix proposal:

in this file: https://github.com/dataesr/react-dsfr/blob/master/src/components/interface/SearchBar/SearchBar.js
Current button:

      <button
        type="submit"
        onClick={() => onSearch(text)}
        className={_classNameButton}
        title={buttonLabel}
      >

Fixed button:

      <button
        type="button"
        onClick={() => onSearch(text)}
        className={_classNameButton}
        title={buttonLabel}
      >

Thanks @jmunozz for the issue. What do you think about adding a type props instead? By default it would be setted to button?

yeah why not ,or a as prop. I saw that sometimes.

Last patch version integrates the event parameter onClick={(event) => onSearch(event, text)} so it's possible to event.preventDefault()