Skip to content

Commit

Permalink
fix: properly handle states for processed_text elements
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Dec 17, 2019
1 parent d5d2afe commit 1874c6b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/Webform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import axios from 'axios'
import { graphql } from 'gatsby'

import { getAttributeValue, formToJSON } from './utils'
import { WebformDebug, WebformInput, WebformSelect, WebformTextarea, WebformCheckbox, WebformCheckboxGroup } from './components'
import {
WebformDebug,
WebformInput,
WebformSelect,
WebformTextarea,
WebformCheckbox,
WebformCheckboxGroup,
WebformText
} from './components'

export const DEFAULT_SUBMIT_LABEL = 'Submit'

Expand Down Expand Up @@ -145,7 +153,7 @@ export function renderWebformElement(element: WebformElement, error?: string, Cu
case 'select':
return <WebformSelect element={element} {...customComponentAPI} />
case 'processed_text':
return <div dangerouslySetInnerHTML={{ __html: getAttributeValue('#text', element) || '' }} />
return <WebformText element={element} {...customComponentAPI} />
// Submit button
case 'webform_actions':
return (
Expand Down
18 changes: 18 additions & 0 deletions src/components/WebformText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'

import { WebformCustomComponent } from '..'
import { useWebformElement } from '../utils'

import WebformElementWrapper from './WebformElementWrapper'

export const WebformText: WebformCustomComponent = ({ element, error }) => {
const [, settings] = useWebformElement(element, {})

return (
<WebformElementWrapper settings={settings} error={error}>
<div dangerouslySetInnerHTML={{ __html: settings.attributes.text || '' }} />
</WebformElementWrapper>
)
}

export default WebformText
12 changes: 11 additions & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import WebformTextarea from './WebformTextarea'
import WebformCheckbox from './WebformCheckbox'
import WebformCheckboxGroup from './WebformCheckboxGroup'
import WebformElementWrapper from './WebformElementWrapper'
import WebformText from './WebformText'
import WebformDebug from './WebformDebug'

export { WebformInput, WebformSelect, WebformTextarea, WebformCheckbox, WebformCheckboxGroup, WebformElementWrapper, WebformDebug }
export {
WebformInput,
WebformSelect,
WebformTextarea,
WebformCheckbox,
WebformCheckboxGroup,
WebformElementWrapper,
WebformText,
WebformDebug
}

0 comments on commit 1874c6b

Please sign in to comment.