itsjavi/bootstrap-colorpicker

useAlpha changes formats from RGBA to RGB if alpha is 1

Open

#322 opened on Dec 7, 2020

View on GitHub
 (2 comments) (0 reactions) (0 assignees)JavaScript (1,379 stars) (372 forks)batch import
bughelp wanted

Description

Description

If the config useAlpha=true has been set, an alpha value of 1 is excluded from the result. This is a bug because it means that the tool returns RGBA formatted data only when there is an alpha value less than one, but if the alpha is 1 (100% opaque) then the result format is changed to simple RGB.

While this functionality may be acceptable for some loosely-defined use cases (web designers), it is opinionated compared to earlier versions of colorpicker and now violates the rule of lease surprise.

If this is truly intended(?) by the author, there should be a way to enforce that the format selected in the options is the one used. ie. forceFormat: true

Context

  • bootstrap-colorpicker version: 3.2.0
  • bootstrap version: 4.5.3
  • jQuery version: 3.5.1
  • Browser name and version: Crome/Brave Chromium 87.0.4280.88 (Official Build) (x86_64)
  • Operative System name an version: OSX 10.15.7

Expected behavior

The flags userAlpha and format when used in combination should ALWAYS set the result value to an RGBA formatted string.

	$('.colorpicker').colorpicker({
		format: "rgba",
		useAlpha: true
	});

Actual behavior

The format of the returned string becomes RBG (no alpha) if the alpha value is 1

Live Example

This is visible on the project's own demo page on any of the examples that return RGB(and sometimes A) https://itsjavi.com/bootstrap-colorpicker/tutorial-Basics.html

Contributor guide