Skip to content

Commit

Permalink
Make onChange prop reactive (closes samuelmeuli#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmeuli committed May 29, 2019
1 parent 0e0b4e1 commit b20fab8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The following props can be passed to the `FontPicker` component:
- **`limit`**: Maximum number of fonts to display in the list (the least popular fonts will be omitted). Default: `50`
- **`sort`**: Sorting attribute for the font list. Possible values: `"alphabet", "popularity"`. Default: `"alphabet"`

_Currently, only the `activeFontFamily` and `sort` props are reactive._
_Currently, only the `activeFontFamily`, `onChange` and `sort` props are reactive._

## Development

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"release": "np"
},
"dependencies": {
"font-picker": "^3.0.3"
"font-picker": "^3.1.0"
},
"peerDependencies": {
"@types/react": "^16.8.10",
Expand Down
11 changes: 8 additions & 3 deletions src/FontPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ export default class FontPicker extends PureComponent<Props, State> {
* call this.setActiveFontFamily with the new font
*/
componentDidUpdate(prevProps: Props): void {
const { activeFontFamily: fontFamilyProps } = this.props;
const { activeFontFamily, onChange } = this.props;

// If active font prop has changed: Update font family in font manager and component state
if (fontFamilyProps !== prevProps.activeFontFamily) {
this.setActiveFontFamily(fontFamilyProps);
if (activeFontFamily !== prevProps.activeFontFamily) {
this.setActiveFontFamily(activeFontFamily);
}

// If onChange prop has changed: Update onChange function in font manager
if (onChange !== prevProps.onChange) {
this.fontManager.setOnChange(onChange);
}
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4491,10 +4491,10 @@ focus-lock@^0.6.3:
resolved "https://registry.yarnpkg.com/focus-lock/-/focus-lock-0.6.4.tgz#066af3ed5875d85745ab45ef4fbbb43e8a73514a"
integrity sha512-+waElh6m7dbNmEabXQIblZjJMIRQOoHMNqB8RZkyemK+vN1XQ9uHLi740DVwTcK5fzAq3g+tBglLjIqUDHX/Og==

font-picker@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/font-picker/-/font-picker-3.0.3.tgz#0eaa8b26f26ea1fdab4955c4fb476df56e27e680"
integrity sha512-j+Q8sz54yVHhdKfq8hAHec+Jdk+CMZZISPjal8G2MS3wXfb0+OrDTuA3X7N9J3TdPivsU3+xTar+/QbgCA2+NA==
font-picker@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/font-picker/-/font-picker-3.1.0.tgz#587afeb46517d3788adbe538d3823c8c6bc2b5df"
integrity sha512-OB5gPtAoSY0CVfolwKd3PXaKl59F0QeP6+Ylt+4js0o1JkKGjvON5MO8lUlYq6VLPJlWx8l/ZmUrvHcAu94CJg==

for-in@^0.1.3:
version "0.1.8"
Expand Down

0 comments on commit b20fab8

Please sign in to comment.