Skip to content

Commit

Permalink
Add <span> tag to (optional) suffix for customization (#7103)
Browse files Browse the repository at this point in the history
* Add <span> tag to (optional) suffix for customization

With the <span> (or any) tag we can add CSS like:

```css
body {
  [class*=FieldLabel-fieldLabel] span {
    display: none;
  }
}
```

to hide or customize the _(optional)_ suffix.

It'll specially useful when majority of the fields are optional, we can also use CSS :has to select required fields and add a _*_ for example.

* Update EditorControl.js

* chore: format

* chore: preventing empty space on field label

* Update EditorControl.js

* test: remove extra space from expected result in e2e test

---------

Co-authored-by: Anze Demsar <[email protected]>
Co-authored-by: Martin Jagodic <[email protected]>
  • Loading branch information
3 people authored Mar 29, 2024
1 parent a07a85b commit dd31fcf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/markdown_widget_code_block_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function codeBlock(content) {
<div>
<div></div>
<div>
<div><label>Code Block </label>
<div><label>Code Block</label>
<div><button><span><svg>
<path></path>
</svg></span></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ function LabelComponent({ field, isActive, hasErrors, uniqueFieldId, isFieldOpti
const label = `${field.get('label', field.get('name'))}`;
const labelComponent = (
<FieldLabel isActive={isActive} hasErrors={hasErrors} htmlFor={uniqueFieldId}>
{label} {`${isFieldOptional ? ` (${t('editor.editorControl.field.optional')})` : ''}`}
{isFieldOptional ? (
<>
{label}
<span>{` (${t('editor.editorControl.field.optional')})`}</span>
</>
) : (
label
)}
</FieldLabel>
);

Expand Down

0 comments on commit dd31fcf

Please sign in to comment.