Skip to content

Intelligent and more correct Html addCssClass #7896

@kartik-v

Description

@kartik-v

I will be submitting a PR for improving and making the Html::addCssClass more intelligent and more practical to use for all use cases - similar or better than jquery addClass.

Enhancements:

  • Parse the original $options['class'] correctly irrespective of whitespaces (tabs, newlines or spaces)
  • Parse the $class param correctly irrespective of whitespaces (tabs, newlines or spaces)
  • If the $class property is separated by spaces... it will validate each class separately already added and
  • Intelligently do not append css class if it already exists irrespective of the whitespace

Current Implementation

Example

$options = ['class' => '    kartik']; // note the whitespace
Html::addCssClass($options, ' hide    kartik  robot');
Html::addCssClass($options, "\tkartik   hide fancy    box     holy");

Output

// generated output
$options['class'] =  '    kartik  hide    kartik  robot         kartik   hide fancy    box     holy';

Proposed Implementation (After PR Change)

Example

$options = ['class' => '    kartik']; // note the whitespace
Html::addCssClass($options, ' hide    kartik  robot');
Html::addCssClass($options, "\tkartik   hide fancy    box     holy");

Output

// generated output
$options['class'] =  'kartik hide robot fancy box holy';

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions