Skip to content

Commit 2665890

Browse files
committed
1.1.2; Fixed incorrect onCursorDropdownChange name
1 parent 6feaabc commit 2665890

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { WithCursorDropdown, CursorDropdown } from "react-cursor-dropdown";
2121
import SomeListComponent from "SomeListComponent";
2222

2323
const Input = props => <input {...props} />;
24-
const InputCursorDropdown = WithCursorDropdown(Input);
24+
const InputWithCursorDropdown = WithCursorDropdown(Input);
2525

2626
class App extends Component {
2727
constructor(props) {
@@ -44,15 +44,15 @@ class App extends Component {
4444

4545
render() {
4646
return (
47-
<InputCursorDropdown
47+
<InputWithCursorDropdown
4848
value={this.state.value}
4949
onChange={this.handleChange}
5050
onCursorDropdownChange={this.handleCursorDropdownChange}
5151
>
5252
// Specify the regex to match against the current word (capture group
5353
required)
5454
<CursorDropdown pattern={/^:(\w*)$/} component={SomeListComponent} />
55-
</InputCursorDropdown>
55+
</InputWithCursorDropdown>
5656
);
5757
}
5858
}

example/src/App.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class App extends Component {
3333
});
3434
};
3535

36-
this.handleDropdownChange = ({ value, cursor }) => {
36+
this.handleCursorDropdownChange = ({ value, cursor }) => {
3737
this.setState({
3838
value:
3939
this.state.value.substring(0, cursor.start) +
@@ -85,7 +85,7 @@ export default class App extends Component {
8585
<InputCursorDropdown
8686
value={this.state.value}
8787
onChange={this.handleChange}
88-
onDropdownChange={this.handleDropdownChange}
88+
onCursorDropdownChange={this.handleCursorDropdownChange}
8989
>
9090
<CursorDropdown
9191
pattern={/^:([\w+-]*)$/}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-cursor-dropdown",
3-
"version": "1.1.0",
3+
"version": "1.1.2",
44
"description": "A React HOC for adding cursor dropdown menus to textareas and text inputs.",
55
"author": "danrpts",
66
"license": "MIT",

src/components/CursorDropdown.jsx

+24-26
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,28 @@ import { DropdownContext } from "./WithCursorDropdown.jsx";
44

55
import styles from "../styles.css";
66

7-
export default class CursorDropdown extends Component {
8-
static propTypes = {
9-
pattern: PropTypes.instanceOf(RegExp).isRequired,
10-
component: PropTypes.oneOfType([
11-
PropTypes.node.isRequired,
12-
PropTypes.func.isRequired
13-
])
14-
};
15-
16-
render() {
17-
return (
18-
<DropdownContext.Consumer>
19-
{context => {
20-
const { cursor, handleDropdownChange } = context;
21-
// NOTE: the provided regex needs to have a capture group
22-
const match = cursor.value.match(this.props.pattern);
23-
return match
24-
? React.createElement(this.props.component, {
25-
filterText: match[1],
26-
onChange: handleDropdownChange
27-
})
28-
: null;
29-
}}
30-
</DropdownContext.Consumer>
31-
);
32-
}
7+
export default function CursorDropdown(props) {
8+
return (
9+
<DropdownContext.Consumer>
10+
{context => {
11+
const { cursor, handleCursorDropdownChange } = context;
12+
// NOTE: the provided regex needs to have a capture group
13+
const match = cursor.value.match(props.pattern);
14+
return match
15+
? React.createElement(props.component, {
16+
filterText: match[1],
17+
onChange: handleCursorDropdownChange
18+
})
19+
: null;
20+
}}
21+
</DropdownContext.Consumer>
22+
);
3323
}
24+
25+
CursorDropdown.propTypes = {
26+
pattern: PropTypes.instanceOf(RegExp).isRequired,
27+
component: PropTypes.oneOfType([
28+
PropTypes.node.isRequired,
29+
PropTypes.func.isRequired
30+
])
31+
};

src/components/WithCursorDropdown.jsx

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ function WithCursorDropdown(WrappedComponent) {
99
class InputWithCursorDropdown extends Component {
1010
// TODO:
1111
// static propTypes = {
12-
// onDropdownChange: PropTypes.func,
12+
// onCursorDropdownChange: PropTypes.func,
1313
// forwardedRef: PropTypes.node
1414
// };
1515

1616
constructor(props) {
1717
super(props);
1818
this.wrapperRef = React.createRef();
19-
this.handleDropdownChange = this.handleDropdownChange.bind(this);
19+
this.handleCursorDropdownChange = this.handleCursorDropdownChange.bind(
20+
this
21+
);
2022
this.state = {
2123
cursor: {
2224
word: { value: "", start: 0, end: 0 },
@@ -32,8 +34,8 @@ function WithCursorDropdown(WrappedComponent) {
3234
: this.wrapperRef.current.firstChild;
3335
}
3436

35-
handleDropdownChange(value) {
36-
this.props.onDropdownChange({
37+
handleCursorDropdownChange(value) {
38+
this.props.onCursorDropdownChange({
3739
value,
3840
cursor: this.state.cursor.word
3941
});
@@ -63,7 +65,7 @@ function WithCursorDropdown(WrappedComponent) {
6365
render() {
6466
const {
6567
children,
66-
onCursorDropdownChange, // just toremove from passed remainingProps
68+
onCursorDropdownChange, // just to remove from passed remainingProps
6769
forwardedRef,
6870
...remainingProps
6971
} = this.props;
@@ -83,7 +85,7 @@ function WithCursorDropdown(WrappedComponent) {
8385
<DropdownContext.Provider
8486
value={{
8587
cursor: this.state.cursor.word,
86-
handleDropdownChange: this.handleDropdownChange
88+
handleCursorDropdownChange: this.handleCursorDropdownChange
8789
}}
8890
>
8991
{children}

0 commit comments

Comments
 (0)