Skip to content

Commit

Permalink
Fix UI bugs (#143)
Browse files Browse the repository at this point in the history
* Fix cursor position when setting read only with a default value

* Pass anchorLink className to Link component

* Add className to anchor tag

* Move default style to anchorLink class

* Update theme example

* Update package version
  • Loading branch information
niuware authored Jun 17, 2020
1 parent 8f21c49 commit 20603e3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions examples/theme/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Object.assign(defaultTheme, {
width: "inherit",
position: "absolute",
top: "20px"
},
anchorLink: {
color: "#333333"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mui-rte",
"version": "1.20.0",
"version": "1.21.0",
"description": "Material-UI Rich Text Editor and Viewer",
"keywords": [
"material-ui",
Expand Down
11 changes: 8 additions & 3 deletions src/MUIRichTextEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const styles = ({ spacing, typography, palette }: Theme) => createStyles({
},
anchorLink: {
textDecoration: "underline",
color: palette.secondary.main
color: "inherit"
},
toolbar: {
},
Expand Down Expand Up @@ -309,7 +309,11 @@ const MUIRichTextEditor: RefForwardingComponent<TMUIRichTextEditorRef, IMUIRichT
style: customStyleMap,
block: DefaultDraftBlockRenderMap.merge(blockRenderMap, Immutable.Map(customBlockMap))
})
setEditorState(EditorState.moveFocusToEnd(editorState))
if (props.readOnly === true) {
setEditorState(editorState)
} else {
setEditorState(EditorState.moveFocusToEnd(editorState))
}
toggleMouseUpListener(true)
return () => {
toggleMouseUpListener()
Expand Down Expand Up @@ -754,7 +758,8 @@ const MUIRichTextEditor: RefForwardingComponent<TMUIRichTextEditorRef, IMUIRichT
const contentState = editorState.getCurrentContent()
let replaceEditorState = editorState
const data = {
url: url
url: url,
className: classes.anchorLink
}

if (urlKey) {
Expand Down
8 changes: 2 additions & 6 deletions src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ type TLinkProps = {
}

const Link: FunctionComponent<TLinkProps> = (props) => {
const { url } = props.contentState.getEntity(props.entityKey).getData()
const { url, className } = props.contentState.getEntity(props.entityKey).getData()
return (
<a
href={url}
style={{
textDecoration: "underline",
color: "inherit"
}}
className="editor-anchor"
className={`${className} editor-anchor`}
target="_blank"
>
{props.children}
Expand Down

0 comments on commit 20603e3

Please sign in to comment.