Comments (9)
Thanks for the response. Good to hear that you are dropping the naming/coding conventions in favour of HTML conventions 👍.
Regarding the components, you can have look at my components (https://github.com/react-fabric/react-fabric/tree/development/src), they're all completely dump and rely only on props (expect SearchBox because the css needs a hover state). I'm also thinking about deprecating the project and start contributing here since they basically accomplish the same thing.
For the onChanged
callback, how about renaming it to onValueChange: (value:any) => void
and supporting the original onChange: (e:React.InputEvent) => void
.
from fluentui.
As @kmees mentioned, the standard onChange: (e:React.InputEvent) => void
callback implementation is important. There is no way we can reference the changed element without event: React.InputEvent
(or let me know if there is a way).
from fluentui.
Thanks for the feedback, it's helpful to get another pair of eyes on this. I agree with pretty much all of your feedback. A couple of things here:
Regarding "as dumb as possible" 100% yes. We are learning this with many of the controls to extract out dumber sub components; there are a lot of changes coming to reduce/refactor some of these to make cleaner implementations. In some cases we can get away with stateless if we can have React's underlying DOM abstraction do it for us, but not always.
First we are actively cleaning up props that feel "different" from the default HTML attributes without a good reason. Checkbox is definitely an example that hasn't been updated to this standard yet. Originally, Toggle had an isToggled property that we renamed to "checked" to be consistent with the default input HTML element. Toggle has been scrubbed but there are still a few left overs to make consistent; we'll do it.
For background: we have a general javascript coding convention to use the "is, are, should" qualifier prefix for boolean flags, but HTML standards conflict here which is to not use qualifiers. We also have a general rule to use positive variable names like "isVisible" instead of negative "isHidden", but this again conflicts with HTML which uses "disabled" and "hidden" flags. So we've decided that for flags, we will try to follow the HTML convention as much as possible. Not everything has been updated, so if you see contract changes and want to submit an issue, or even better a PR, we'll try to get that patched up.
The onChange vs onChanged naming convention was intentional, but we're open to making it more consistently use onChange. The issue is that in these onChanged callbacks, we're passing back additional metadata to the caller. Toggle for example passes back the checked state. TextField may pass in the value. We don't want the caller to assume ev.target.value is the way to read the value. So by changing the definition we may be changing the expectations. E.g. a user expects onChange to take in a React.InputEvent , but now the event is the 3rd argument. But... well, there is also ambiguity here with onChange vs onChanged so I can see it being confusing either way.
I will look into the controlled/uncontrolled switching. We have a separate issue logged to address and will see if I can scrub these in that process.
Factoring out the validation from text field has definitely been discussed already and agreed on. We should open a separate issue to track this.
from fluentui.
I am currently trying to implement a TextField and I can't figure out how to reference the current element when updating the appropriate values in the state. The old way, like mentioned above, was to use onChange and event.target.name. What is the current workaround for this?
Edit: Thanks to kmees for the workaround.
Create a OnChangeHandler for the TextField component. Like so...
const createOnChangedHandler = (name) => (value) => { /* do something with name and value here, i.e. */ }
Then call the onChangedHandler from your onChanged event.
<TextField onChanged={createOnChangedHandler('foo')} value={/* value for foo */} />
from fluentui.
@gabrielruss did you find a way to do it?
from fluentui.
@notgiorgi Yes, I am currently using the method I described in my previous comment. I believe you could also create a parent component for the TextField (or any component type) and specify a name property on the parent component. Then on the child component's onChanged method, call this.props.onChanged and pass this.props.name. This is a strange method...but it works currently.
Here is the onChanged method I have for my child component.
private _handleChange (value: IChoiceGroupOption) { this.props.onChanged(this.props.name, value.text); }
from fluentui.
@gabrielruss It got fixed #809
from fluentui.
It got fixed in Jan so closing it.
from fluentui.
The above workaround does the job. This is a littler clearer:
handleInputChange = name => value => {
this.setState({
[name]: value
});
}
---
<TextField
label='Last Name'
value={this.state.lastName}
onChanged={this.handleInputChange('lastName')}
/>
from fluentui.
Related Issues (20)
- [Bug]: InfoLabel does not respect `mountNode` property HOT 6
- [Bug]: Switch disappears on mouse-down in high contrast (forced colors)
- Deprecated props do not have any indication they are deprecated in storybook
- [Bug]: In IOS, People picker fly out pannel is closing when user minimize the keypad & not able to select last user HOT 1
- [Bug]: Documentation for Dropdown is missing for some properties
- [Feature]: Allow binding to different Cultures for NumberField
- [Bug]: @fluentui/react-datepicker-compat and @fluentui/react-timepicker-compat css are broken HOT 2
- [Bug]: react-tag-picker-preview : pressing space on keyboard causing pickier closing HOT 2
- [Feature]: Can we have a paginated/Infinite scrolling ComboBox. HOT 1
- [Bug]: Skeleton uses main thread for animation, causes jank under CPU load HOT 1
- [Feature]: Can we add props "focusMode" to DataGridHeaderCell component?
- [Bug]: Chart tooltip not visible when rendered on OverlayDrawer (on drawer reopen) HOT 1
- [Bug]: Charting: customDateTimeFormatter and timeFormatLocale does not display the correct date for x axis HOT 7
- [Bug]: Tooltip scrolling issues with long text HOT 1
- [Bug]: Charting: customDateTimeFormatter and timeFormatLocale does not display the correct date for x axis (duplicate from comment) HOT 1
- [Bug]: heavy webpack warnings logs in all cypress tests
- Create donut chart and line chart as web components
- [Feature]: Exclude Typescript types from `no-restricted-globals` eslint rule
- [Bug]: Accessibility issue while using @fluentui/react/lib/GroupedList HOT 3
- [Bug]: Dropdown does not have focus indicators in Strict Mode
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluentui.