Skip to content

[4.0] Render label#25085

Merged
wilsonge merged 4 commits intojoomla:4.0-devfrom
brianteeman:renderlabel
Jun 3, 2019
Merged

[4.0] Render label#25085
wilsonge merged 4 commits intojoomla:4.0-devfrom
brianteeman:renderlabel

Conversation

@brianteeman
Copy link
Copy Markdown
Contributor

There is an option "hiddenLabel" for a form field. But instead of "hiding" the label it doesn't render the label at all. This causes accessibility issues because every form field input must have an associated label.

This PR changes it so that instead of the label not being rendered at all it is rendered with a class of sr-only instead.

Testing

Add the following field to any form

		<field
			name="test"
			type="text"
			label="Hidden"
			hiddenLabel="true"
		/>

Before and After applying the PR there will be no visual change BUT if you view the source you will see that the code has changed

Before

<div class="control-group">
	<div class="controls">
		<input type="text" name="jform[test]" id="jform_test" value="" class="form-control">
	</div>
</div>

After

<div class="control-group">
	<div class="control-label sr-only">
	        <label id="jform_test-lbl" for="jform_test">Hidden</label>
	</div>
	<div class="controls has-success">
		<input type="text" name="jform[test]" id="jform_test" value="" class="form-control valid form-control-success" aria-invalid="false">
	</div>
</div>

There is an option "hiddenLabel" for a form field. But instead of "hiding" the label it doesn't render the label at all. This causes accessibility issues because every form field input must have an associated label.

This PR changes it so that instead of the label not being rendered at all it is rendered with a class of sr-only instead.

### Testing
Add the following field to any form
`
		<field
			name="test"
			type="text"
			label="Hidden"
			hiddenLabel="true"
		/>
'
Before and After applying the PR there will be no visual change BUT if you view the source you will see that the code has changed

### Before
`
<div class="control-group">
	<div class="controls">
		<input type="text" name="jform[test]" id="jform_test" value="" class="form-control">
	</div>
</div>
`
### After
`
<div class="control-group">
	<div class="control-label sr-only">
        <label id="jform_test-lbl" for="jform_test">Hidden</label>
	</div>
	<div class="controls has-success">
	<input type="text" name="jform[test]" id="jform_test" value="" class="form-control valid form-control-success" aria-invalid="false">
	</div>
</div>
`
$class = empty($options['class']) ? '' : ' ' . $options['class'];
$rel = empty($options['rel']) ? '' : ' ' . $options['rel'];
$id = $name . '-desc';
$hide = empty($options['hiddenLabel']) ? '' : ' ' . "sr-only";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brianteeman What happens if someone adds a field where the hiddenLabel option is not empty but false: hiddenLabel="false"?

I think your code right now would also set the sr-only class in that case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, on the other hand I see it is like that without your PR, too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly ;)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you wanna fix that, too? or wanna leave this pr as it is and i shall test?

@richard67
Copy link
Copy Markdown
Member

I have tested this item ✅ successfully on f855283

I tested this with the TinyMCE editor plugin, which has such a field (field with name="configuration" in fieldset with name="basic").
Without this PR, the field is not rendered. With this PR, it is rendered with sr-only class.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25085.

@ghost ghost added the a11y Accessibility label Jun 2, 2019
@ghost ghost changed the title [4.0] Render label [a11y] [4.0] Render label Jun 2, 2019
Co-Authored-By: Quy <quy@fluxbb.org>
@richard67
Copy link
Copy Markdown
Member

I have tested this item ✅ successfully on de6db06


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25085.

1 similar comment
@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jun 2, 2019

I have tested this item ✅ successfully on de6db06


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25085.

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jun 2, 2019

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25085.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jun 2, 2019
Co-Authored-By: Quy <quy@fluxbb.org>
@richard67
Copy link
Copy Markdown
Member

I have tested this item ✅ successfully on faa2a56


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25085.

@wilsonge wilsonge merged commit de85fa4 into joomla:4.0-dev Jun 3, 2019
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jun 3, 2019
@wilsonge
Copy link
Copy Markdown
Contributor

wilsonge commented Jun 3, 2019

Added docs required because technically we have a b/c break here requiring the label on hiddenLabel fields (I think the chances are low anyone's doing that but anyhow...)

@brianteeman
Copy link
Copy Markdown
Contributor Author

Thanks

@brianteeman brianteeman deleted the renderlabel branch June 3, 2019 14:44
@zero-24 zero-24 added this to the Joomla 4.0 milestone Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a11y Accessibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants