GA-MO / react-confirm-alert

react component confirm dialog.
https://ga-mo.github.io/react-confirm-alert/demo/
MIT License
272 stars 105 forks source link

Change 'string' PropTypes to 'node' #8

Closed pascallaprade closed 6 years ago

pascallaprade commented 6 years ago

The prop types for your component only allow string to be passed for the title, message, confirm label and cancel label. However, the code clearly supports anything that can be rendered, and providing a span element, for instance, works perfectly.

The prop types should be less restrictive, and be PropTypes.node instead of PropTypes.string.

GA-MO commented 6 years ago

@pascallaprade Thank you, Solved in v2

michalpokojski commented 5 years ago

I think it still requires a string while working with any node.

my case:

confirmAlert({
      title: <div css={{ marginBottom: 20 }}>{t('catalogue.confirmationDialogue.confirmHeader')}</div>,
      message: <div>
        {t('catalogue.confirmationDialogue.from')}
        <br /><br />
        <b>{props.children || 'n/a'}</b>
        <br /><br />
        {t('catalogue.confirmationDialogue.to')}
        <br /><br />
        <b>{text}</b>
      </div>,
      onKeypressEscape: handleInputBlur,
      buttons: [
        {
          label: t('catalogue.confirmationDialogue.yes'),
          onClick: async () => {
            await props.editItem({ itemId: props.item.id, field: props.fieldName, value: text })
            setEditing(false)
          }
        },
        {
          label: t('catalogue.confirmationDialogue.no'),
          onClick: handleInputBlur
        }
      ]
    })

throwing errors for both title and message

Failed prop type: Invalid prop `title` of type `object` supplied to `ReactConfirmAlert`, expected `string`.

and still rendering perfectly

GA-MO commented 5 years ago

@michalpokojski This case you can use prop childrenElement instead of title and message example:

   confirmAlert({
      childrenElement: () => (
        <>
          <h2>Title</h2>
          <div>Some message</div>
        </>
      ),
      buttons: [...]
    });