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

BaseAutoFill: Fix a bug where BaseAutoFill would not work with composed languages #3713

Merged
merged 10 commits into from
Jan 23, 2018

Conversation

joschect
Copy link
Contributor

Pull request checklist

  • Addresses an existing issue: Fixes #0000
  • Include a change request file using $ npm run change

Description of changes

BaseAutoFill: Fix a bug where BaseAutoFill would not work with composed languages

Focus areas to test

(optional)

@joschect joschect requested a review from martellaj January 16, 2018 19:24
Copy link
Contributor

@dmichon-msft dmichon-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that values in this.props.enableAutoFillOnKeyPress still bypass the composition check, especially since the up and down arrows (which are the defaults) are the default keys for selecting inputs in the composition window.

@@ -141,6 +141,19 @@ export class BaseAutoFill extends BaseComponent<IBaseAutoFillProps, IBaseAutoFil
this._inputElement.setSelectionRange(0, 0);
}

@autobind
private _onCompositionStart(ev: React.CompositionEvent<HTMLInputElement>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should have a comment somewhere explaining what 'composition' is

if (this.props.enableAutoFillOnKeyPress!.indexOf(ev.which) !== -1) {
this._autoFillEnabled = true;
break;
case KeyCodes.left:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left/right cases are identical and can be combined

break;
default:
if (!this._autoFillEnabled) {
if (this.props.enableAutoFillOnKeyPress!.indexOf(ev.which) !== -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing a lot of this.props.foo!
Remember that Partial exists now. Maybe you can make an interface of IPropsAllRequired, and expose Partial as the actual props the component takes, and then use IPropsAllRequired internally.

if (value && (ev.target as HTMLInputElement).selectionStart === value.length && !this._autoFillEnabled && value.length > this._value.length) {
let value: string = this._getCurrentInputValue(ev);
// Right now typing does not have isComposing, once that has been fixed any should be removed.
this._tryEnableAutoFill(value, this._value, (ev.nativeEvent as any).isComposing);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the 'any' is giving warnings, you could also try ev.nativeEvent['isComposing']

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not.

}

private _getCurrentInputValue(ev?: React.FormEvent<HTMLElement>) {
if (ev && ev.target && (ev.target as any).value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of "as any" why not just "as InputElement" (or whatever it's called) since you know what it's going to be

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we really should be using the text coming from the input event. Tests started failing if that wasn't a possibility.

return (ev.target as any).value;
}
let value: string = this._inputElement.value;
return value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return (ev && ev.target && ev.target.value) || this._inputElement.value;

* @param isComposing
* @param isComposed
*/
private _tryEnableAutoFill(newValue: string, oldValue: string, isComposing?: boolean, isComposed?: boolean) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is autofill one or two words? =)

* Attempts to enable autofill. Whether or not autofill is enabled depends on the input value,
* whether or not any text is selected, and only if the new input value is longer than the old input value.
* isComposed is whether or not the new value is a composed value.
* Autofill should never be set to true if the value is composing. Once compositionEnd is called, then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"value is BEING composed"? not sure of the right verbiage here...
also you should describe what composition is

* it should be completed.
* @param newValue
* @param oldValue
* @param isComposing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment on the difference between isComposing and isComposed

Copy link
Contributor

@jspurlin jspurlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to validate that the behavior is not adversely affected for the other fabric components which are composed with BaseAutoFill before checking in

@joschect
Copy link
Contributor Author

Yep! I made sure it worked in combo box as well.

@joschect joschect merged commit 09c29d1 into microsoft:master Jan 23, 2018
chrismohr pushed a commit to chrismohr/office-ui-fabric-react that referenced this pull request Apr 17, 2018
…ed languages (microsoft#3713)

* enable the base auto fill to work with composed languages like Japanese. Also made some small improvements to structure

* adding change file

* removing unecessary import

* fix lint

* Update BasePicker Snap

* Fixing comments and minor bug in firefox

* Make onchange better and update snaps

* adding in comments

* fixing comments

* small code cleanup
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants