|
| 1 | +# Migrating from v1 to v2 |
| 2 | +Most of the controls have no breaking changes when moving from v1 to v2. However, some APIs were changed to make the libary more stable and controls behavior more even. |
| 3 | +Also, we've bumped up React and Fluent UI versions used in the library. It means you will need to update `package.json` file in your SPFx projects. |
| 4 | +The below guide is an overview of what it takes to migrate from v1 to v2. If we missed something, please let us know in the issues list so we can update the guide. Thanks! |
| 5 | + |
| 6 | +## v2 Supports SharePoint Online Only |
| 7 | +v2 of Reusable Controls is based on SharePoint Framework 1.11 and, as a result, does not support SharePoint On-Premise. **Please, use v1 if you plan to deploy your soluition on-prem.** |
| 8 | + |
| 9 | +## React and Fluent UI versions |
| 10 | +v2 of Reusable Controls uses React.js v16.8.5 and Fluent UI (Office UI Fabric React) v6.189.2. |
| 11 | +Please, update the `package.json` accordingly: |
| 12 | +```json |
| 13 | +"dependencies": { |
| 14 | + // other dependencies |
| 15 | + "@types/react": "16.8.8", |
| 16 | + "@types/react-dom": "16.8.3", |
| 17 | + "office-ui-fabric-react": "6.189.2", |
| 18 | + "react": "16.8.5", |
| 19 | + "react-dom": "16.8.5" |
| 20 | + }, |
| 21 | + "resolutions": { |
| 22 | + "@types/react": "16.8.8" |
| 23 | + }, |
| 24 | +``` |
| 25 | + |
| 26 | +## APIs Changes |
| 27 | +### PeoplePicker |
| 28 | +`isRequred` is renamed to `required`.<br/> |
| 29 | +The property has been renamed to use the common approach for mandatory field naming. |
| 30 | + |
| 31 | +`errorMessage` represents static error message to be displayed in the control. <br /> |
| 32 | +In v1 `errorMessage` is used to provide the text that will be displayed if the field is set as `required` and no value is selected. |
| 33 | +In v2 you can use this property to statically display error message for whatever reason. |
| 34 | +```typescript |
| 35 | +/** |
| 36 | + * Static error message displayed below the text field. Use onGetErrorMessage to dynamically change the error message displayed (if any) based on the current value. errorMessage and onGetErrorMessage are mutually exclusive (errorMessage takes precedence). |
| 37 | + */ |
| 38 | + errorMessage?: string; |
| 39 | +``` |
| 40 | + |
| 41 | +`onGetErrorMessage` to get error message dynamically.<br /> |
| 42 | +The method is used to get the validation error message and determine whether the input value is valid or not. Mutually exclusive with the static string errorMessage (it will take precedence over this). |
| 43 | +```typescript |
| 44 | +/** |
| 45 | + * The method is used to get the validation error message and determine whether the picker value is valid or not. |
| 46 | + * Mutually exclusive with the static string errorMessage (it will take precedence over this). |
| 47 | + * |
| 48 | + * When it returns string: |
| 49 | + * - If valid, it returns empty string. |
| 50 | + * - If invalid, it returns the error message string and the picker will |
| 51 | + * show an error message below the picker. |
| 52 | + * |
| 53 | + * When it returns Promise<string>: |
| 54 | + * - The resolved value is display as error message. |
| 55 | + * - The rejected, the value is thrown away. |
| 56 | + * |
| 57 | + */ |
| 58 | + onGetErrorMessage?: (items: IPersonaProps[]) => string | Promise<string>; |
| 59 | +``` |
| 60 | + |
| 61 | +`showRequiredError` has been deleted.<br /> |
| 62 | +Use `errorMessage` or `onGetErrorMessage` to provide the error message. |
| 63 | + |
| 64 | +`selectedItems` is renamed to `onChange`<br /> |
| 65 | +`onChange` better describes the purpose of the property. |
| 66 | + |
0 commit comments