Add missing wrapper and properties for the Textarea component

Created on 17 August 2023, about 1 year ago
Updated 10 September 2023, about 1 year ago

Problem/Motivation

Textarea component needs a wrapper for textarea
Why
This wrapper is needed from ACE editor js https://git.drupalcode.org/project/ace_editor/-/blob/8.x-1.x/js/editor.js

            var editor_dummy = "<pre id='"+ace_editor_id+"'></pre>";
            $element.closest(".form-textarea-wrapper").append(editor_dummy);

Proposed resolution

1- Use HTML block using layout builder

Having the following:

Properties:

  • resizable: (none|vertical|horizontal|both) An indicator for whether the textarea is resizable.
  • required: (true|false) An indicator for whether the textarea is required.
  • value: The textarea content.
  • rows: Specifies the number of visible text lines.
  • cols: Specifies the visible width in average character widths.
  • maxlength: Specifies the maximum length (in characters) of a text area
  • placeholder: Specifies a short hint that describes the expected value of a text area.
  • readonly: Specifies whether the control may be modified by the user.
  • disabled: Disables the control for user input.
  • wrapper_html_tag: The HTML tag for the wrapper.
  • wrapper_utility_classes: An array of utility classes. Use to add extra Bootstrap utility classes or custom CSS classes over the wrapper div to this component.
  • utility_classes: An array of utility classes. Use to add extra Bootstrap utility classes or custom CSS classes over the form element to this component.

Attributes:

  • wrapper_attributes: A list of HTML attributes for the wrapper element
  • attributes: A list of HTML attributes for the element.

Slots:

  • N/A

📌 Add standard Drupal heading for the Textarea template with Theme override for a textarea #type form element Fixed

Remaining tasks

  • ✅ File an issue about this project
  • ✅ Addition/Change/Update/Fix to this project
  • ✅ Testing to ensure no regression
  • ➖ Automated unit/functional testing coverage
  • ➖ Developer Documentation support on feature change/addition
  • ➖ User Guide Documentation support on feature change/addition
  • ✅ Accessibility and Readability
  • ✅ Code review from 1 Varbase core team member
  • ✅ Full testing and approval
  • ✅ Credit contributors
  • ✅ Review with the product owner
  • ✅ Update Release Notes and Update Helper on new feature change/addition
  • ✅ Release Varbase 10.0.0-beta1 , varbase_components-2.0.0-alpha21

Varbase update type

  • ✅ No Update
  • ➖ Optional Update
  • ➖ Forced Update
  • ➖ Forced Update if Unchanged

User interface changes

Text area - story with wrapper HTML Div Tag

Text area - No wrapper

Text area - Resize both sizes

Text area - Disabled

Text area - Valid

Text area - Invalid

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇯🇴Jordan ahmad abbad Jordan

Live updates comments and jobs are added and updated live.
  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

Sign in to follow issues

Comments & Activities

  • Issue created by @ahmad abbad
  • @ahmad-abbad opened merge request.
  • Status changed to Needs review about 1 year ago
  • 🇯🇴Jordan Rajab Natshah Jordan

    Thanks, Ahmad, for reporting and the MR

    I agree to that. After a quick review

    Let us follow the school of Bootstrap Barrio 5.5.x on this
    https://git.drupalcode.org/project/bootstrap_barrio/-/blob/5.5.x/templat...

    Please, add wrapper_attributes to props

        wrapper_attributes:
          type: Drupal\Core\Template\Attribute
    

    Let us add resizable, required too as props

  • Assigned to Rajab Natshah
  • Status changed to Active about 1 year ago
  • 🇯🇴Jordan Rajab Natshah Jordan

    Drupal 10.1.x core
    https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/includes/fo...
    has the following and the webform module is following with that.

    /**
     * Prepares variables for textarea templates.
     *
     * Default template: textarea.html.twig.
     *
     * @param array $variables
     *   An associative array containing:
     *   - element: An associative array containing the properties of the element.
     *     Properties used: #title, #value, #description, #rows, #cols, #maxlength,
     *     #placeholder, #required, #attributes, #resizable.
     */
    function template_preprocess_textarea(&$variables) {
      $element = $variables['element'];
      $attributes = ['id', 'name', 'rows', 'cols', 'maxlength', 'placeholder'];
      Element::setAttributes($element, $attributes);
      RenderElement::setAttributes($element, ['form-textarea']);
      $variables['wrapper_attributes'] = new Attribute();
      $variables['attributes'] = new Attribute($element['#attributes']);
      $variables['value'] = $element['#value'];
      $variables['resizable'] = !empty($element['#resizable']) ? $element['#resizable'] : NULL;
      $variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL;
    }
    

    Having the following:

    Properties:

    • value: The value in the text.
    • resizable: (true|false) To be able to resize the textarea form field.
    • required: (true|false) To change the filed as required.

    Attributes:

    • attributes
    • wrapper_attributes

    Slots:

    • N/A
  • 🇯🇴Jordan Rajab Natshah Jordan

    find out that Drupal ~10.1.0 core has css styles for components

    Resizable textareas

    /**
     * @file
     * Resizable textareas.
     */
    
    .resize-none {
      resize: none;
    }
    .resize-vertical {
      min-height: 2em;
      resize: vertical;
    }
    .resize-horizontal {
      max-width: 100%;
      resize: horizontal;
    }
    .resize-both {
      max-width: 100%;
      min-height: 2em;
      resize: both;
    }
    
  • 🇯🇴Jordan Rajab Natshah Jordan

    Changed

    resizable: (true|false) An indicator for whether the textarea is resizable.

    to

    resizable: (none|vertical|horizontal|both) An indicator for whether the textarea is resizable.

  • 🇯🇴Jordan Rajab Natshah Jordan

    Drupal ~10.1.0 core is utilizing more properties for the Textarea form element
    https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/includes/fo...
    - element: An associative array containing the properties of the element.
    Properties used: #title, #value, #description, #rows, #cols, #maxlength, #placeholder, #required, #attributes, #resizable.

    From the The TEXTAREA element by w3

    17.7 The TEXTAREA element
    <!ELEMENT TEXTAREA - - (#PCDATA)       -- multi-line text field -->
    <!ATTLIST TEXTAREA
      %attrs;                              -- %coreattrs, %i18n, %events --
      name        CDATA          #IMPLIED
      rows        NUMBER         #REQUIRED
      cols        NUMBER         #REQUIRED
      disabled    (disabled)     #IMPLIED  -- unavailable in this context --
      readonly    (readonly)     #IMPLIED
      tabindex    NUMBER         #IMPLIED  -- position in tabbing order --
      accesskey   %Character;    #IMPLIED  -- accessibility key character --
    

    rows = number [CN]
    This attribute specifies the number of visible text lines. Users should be able to enter more lines than this, so user agents should provide some means to scroll through the contents of the control when the contents extend beyond the visible area.
    cols = number [CN]
    This attribute specifies the visible width in average character widths. Users should be able to enter longer lines than this, so user agents should provide some means to scroll through the contents of the control when the contents extend beyond the visible area. User agents may wrap visible text lines to keep long lines visible without the need for scrolling.

    Adding more properties:

    • rows: Specifies the number of visible text lines. Users should be able to enter more lines than this, so user agents should provide some means to scroll through the contents of the control when the contents extend beyond the visible area.
    • cols: Specifies the visible width in average character widths. Users should be able to enter longer lines than this, so user agents should provide some means to scroll through the contents of the control when the contents extend beyond the visible area. User agents may wrap visible text lines to keep long lines visible without the need for scrolling.
    • maxlength: specifies the maximum length (in characters) of a text area
    • placeholder: Specifies a short hint that describes the expected value of a text area.
    • readonly: Specifies whether the control may be modified by the user.
    • disabled: Disables the control for user input.
  • Assigned to Mohammed J. Razem
  • Status changed to Needs review about 1 year ago
  • Issue was unassigned.
  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed about 1 year ago
Production build 0.71.5 2024