fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

ColorPicker throws error when entering invalid hex

Open SpencerLynn opened this issue 9 years ago • 2 comments

Bug Report

  • Package version(s): v5.7.0
  • Browser and OS versions: I tested in Chrome Version 61.0.3163.100 in Windows 10

Priorities and help requested (not applicable if asking question):

Are you willing to submit a PR to fix? Yes

Requested priority: High

Products/sites affected: All

Describe the issue:

ColorPicker throws an error when an invalid hex string is placed into the hex text field.

The error occurs in the blur function for the hex text field. In the cssColor function, the color will not match any of the options and returns undefined. The calling code then tries to reference property a of undefined and throws an error.

export function cssColor(color: string): IRGB {
  return (_named(color)
    || _hex3(color)
    || _hex6(color)
    || _rgb(color)
    || _rgba(color)
    || _hsl(color)
    || _hsla(color) as IRGB);
}

Actual behavior:

ColorPicker throws an error when invalid hex is entered into hex text field.

Expected behavior:

ColorPicker should not throw an error. Instead, should return to the last valid input.

If applicable, please provide a codepen repro:

If you open the developer console, you'll see an exception thrown. after entering "ff0000s" into the hex text field and tabbing out (or anything to blur the text field).

https://codepen.io/spencerlynn/pen/JywGBr

Also reproduces on: https://developer.microsoft.com/en-us/fabric#/components/colorpicker

SpencerLynn avatar Oct 10 '17 16:10 SpencerLynn

@phkuo could you help here?

dzearing avatar Oct 12 '17 06:10 dzearing

Out tomorrow, I can take a look next week. Probably just needs a falsey check in _updateColor()

phkuo avatar Oct 12 '17 23:10 phkuo