Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composition type compoent #7087

Closed
suhaotian opened this issue Jun 20, 2016 · 8 comments
Closed

Composition type compoent #7087

suhaotian opened this issue Jun 20, 2016 · 8 comments

Comments

@suhaotian
Copy link

suhaotian commented Jun 20, 2016

I write this BaseInput,
some code from draft-js,
problem here: when you click set another value button, the input didn't change.

And I know I shouldn't use defaultValue in BaseInput component, But if not, the compostion type doesn't work correct. And I browser document again, really don't know how to do it.

Have any idea?

BaseInput

Update:

change defaultValue to value:
You can see effect here: demo video

@aweary
Copy link
Contributor

aweary commented Jun 20, 2016

@suhaotian

You should set the value prop on the returned DOM element to props.value so its value is controlled. See http://jsbin.com/pavexeruce/1/edit?js,output

return (React.createElement(type, {
    ...props,
    /* Add the value prop here and it works as you'd expect */
    value: value,
    defaultValue: value,
    onBeforeInput: (e) => {
      textInputData = (textInputData || '') + e.data
    },

@suhaotian
Copy link
Author

suhaotian commented Jun 20, 2016

@aweary Yes!
But when type composition input like,Chinese, it didn't work.....

@suhaotian
Copy link
Author

You can see here: demo video

@zpao
Copy link
Member

zpao commented Jun 20, 2016

@suhaotian Looks like you're using 15.1.0. Does this also happen with 15.0.1?

@hellendag have you heard of any issues with IME lately?

@keyz
Copy link
Contributor

keyz commented Jun 20, 2016

I think this is related to #3926, where onChange event fires while the IME (输入法) string is being constructed.

In your onChange handler:

    onChange: (e) => {
      if (!composing) {                    
        onChange(e.target.value)
      }
    },

When composing === true, the newly inputted value will be discarded since <input/> is controlled.

However, I'm not sure why you need to use onCompositionStart and onCompositionEnd here (a simple onChange might just be enough). Could you elaborate on your use case? @suhaotian

@suhaotian
Copy link
Author

suhaotian commented Jun 21, 2016

@keyanzhang type some Chinese words will fire oncomposition* event, and I don't want fire change event before oncompositionend

@suhaotian
Copy link
Author

suhaotian commented Jun 21, 2016

@zpao Also happen with 15.0.1; Some code from draft-js DraftEditorCompositionHandler.js. Not at all. Maybe we can learn it from vue text., it's work fine with composition input.
The BaseInput work without value. Demo effect here

@suhaotian
Copy link
Author

suhaotian commented Jun 21, 2016

Hey, guys. I solved this proplem !!!

Online work demo: http://output.jsbin.com/basada

Effect: https://youtu.be/K6lXWRv72ok

@keyz keyz closed this as completed Jun 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants