Skip to content

[css-properties-values-api] Allowed Values/Property Validation #851

Open
@Snugug

Description

@Snugug

I'm looking to do something akin to creating constant custom properties for things like style guides, and I thought I was going to be clever hacking it with syntax but that doesn't work for items like colors where I still want browsers to know the property is a color not just a random ident. Ideally, I'd be able to do something like the following:

CSS.registerProperty({
  name: '--my-blue',
  syntax: '<color>',
  inherits: true,
  allowedValues: ['#4285f4'],
});

CSS.registerProperty({
  name: '--highlight-color',
  syntax: '<color>',
  allowedValues: ['#4285f4', '#ea4335', '#fbbc04'],
  initialValue: '#4285f4',
});

Alternatively to this, providing a validation hook that could either be created at registration time or picked up in JavaScript later if using the @property syntax

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions