Office ui fabric in spfx
My toggle onChange event not firing
public render() {
const { columns, isCompactMode, items, selectionDetails, isModalSelection } = this.state;
return (
<Fabric>
<div className={classNames.controlWrapper}>
<Toggle
label="Enable compact mode"
checked={isCompactMode}
onChange={this._onChangeCompactMode.bind(this)}
onText="Compact"
offText="Normal"
styles={controlStyles}
/>
<Toggle
label="Enable modal selection"
checked={isModalSelection}
onChange={this._onChangeModalSelection.bind(this)}
onText="Modal"
offText="Normal"
styles={controlStyles}
/>
<TextField label="Filter by name:" onChange={this._onChangeText.bind(this)} />
</div>
<div className={classNames.selectionDetails}>{selectionDetails}</div>
<MarqueeSelection selection={this._selection}>
<DetailsList
items={items}
compact={isCompactMode}
columns={columns}
selectionMode={isModalSelection ? SelectionMode.multiple : SelectionMode.none}
setKey="set"
layoutMode={DetailsListLayoutMode.justified}
isHeaderVisible={true}
selection={this._selection}
selectionPreservedOnEmptyClick={true}
onItemInvoked={this._onItemInvoked}
enterModalSelectionOnTouch={true}
ariaLabelForSelectionColumn="Toggle selection"
ariaLabelForSelectAllCheckbox="Toggle selection for all items"
/>
</MarqueeSelection>
</Fabric>
);
}
private _onChangeCompactMode = (ev: React.MouseEvent<HTMLElement>, checked: boolean): void => {
console.log("test");
this.setState({ isCompactMode: checked });
}
private _onChangeModalSelection = (ev: React.MouseEvent<HTMLElement>, checked: boolean): void => {
console.log("test1");
this.setState({ isModalSelection: checked });
}
private _onChangeText = (ev: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, text: string): void => {
this.setState({
items: text ? this._allItems.filter(i => i.name.toLowerCase().indexOf(text) > -1) : this._allItems
});
}
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
Have you verified this is only happening in SPFx & that it's not an issue with Fabric React?
Also... need more context: what version of SharePoint Framework are you running, what version of Fabric React / React, etc...
Hi @andrewconnell
below is my package.json file
{
"name": "crud-list",
"version": "0.0.1",
"private": true,
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@microsoft/sp-core-library": "1.7.1",
"@microsoft/sp-lodash-subset": "1.7.1",
"@microsoft/sp-office-ui-fabric-core": "^1.7.1",
"@microsoft/sp-webpart-base": "1.7.1",
"@types/es6-promise": "0.0.33",
"@types/react": "16.4.2",
"@types/react-dom": "16.0.5",
"@types/webpack-env": "1.13.1",
"react": "16.3.2",
"react-dom": "16.3.2"
},
"resolutions": {
"@types/react": "16.4.2"
},
"devDependencies": {
"@microsoft/sp-build-web": "1.7.1",
"@microsoft/sp-tslint-rules": "1.7.1",
"@microsoft/sp-module-interfaces": "1.7.1",
"@microsoft/sp-webpart-workbench": "1.7.1",
"gulp": "~3.9.1",
"@types/chai": "3.4.34",
"@types/mocha": "2.2.38",
"ajv": "~5.2.2"
}
}
I think its working on codepen but its not working in spfx webpart
SPFx v1.7.1 was using Fabric React v5.*... in that version, the event isn't onChange(), it's onChanged(). In the docs, this method shows as deprecated.
On March 14, Microsoft release SPFx v1.8.0 which appears to have bumped the support to Fabric React v6.*. That version may have the onChange() event in it... but I'm not sure.
Issue solved thank u so much @andrewconnell
Hi TusharFork, I'm facing the same issue. My onChange event is not firing on Toggle control. How did you fix this issue?
Can u pls add snippets of ur code and which version u r using
On Fri, Jul 12, 2019, 12:44 PM chinthaka321 [email protected] wrote:
Hi TusharFork, I'm facing the same issue. My onChange event is not firing on Toggle control. How did you fix this issue?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SharePoint/sp-dev-docs/issues/3603?email_source=notifications&email_token=AKQ5MHMVHURBB4WTTP4GIVTP7AVOZA5CNFSM4G6TBACKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZY5GZA#issuecomment-510776164, or mute the thread https://github.com/notifications/unsubscribe-auth/AKQ5MHKLMAGLKB6FIQ4WGDDP7AVOZANCNFSM4G6TBACA .
Also add which spfx version, react and fabric ui version you are using
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues