-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(text-editor): implement label prop #2929
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
:host(limel-text-editor) { | ||
--limel-text-editor-padding: 0.5rem 1rem; | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
} | ||
|
||
limel-markdown { | ||
display: block; | ||
padding: var(--limel-text-editor-padding); | ||
fieldset { | ||
min-width: 0; | ||
min-height: 0; | ||
|
||
:host(limel-text-editor[readonly]) & { | ||
padding-block-start: 0.75rem; | ||
} | ||
} | ||
|
||
@import '../../style/internal/fieldset.scss'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@use './shared_input-select-picker.scss'; | ||
@use '../mixins.scss'; | ||
|
||
$_thickness-of-the-border: 1px; | ||
|
||
fieldset { | ||
box-sizing: border-box; | ||
transition: | ||
border-color 0.2s ease, | ||
background-color 0.2s ease; | ||
border: $_thickness-of-the-border solid; | ||
border-radius: 0.25rem; | ||
|
||
margin-inline-start: 0; | ||
margin-inline-end: 0; | ||
padding-block-start: 0; | ||
padding-inline-start: 0.75rem; | ||
padding-inline-end: 0.75rem; | ||
padding-block-end: 0.75rem; | ||
|
||
&:not([disabled]) { | ||
border-color: shared_input-select-picker.$lime-text-field-outline-color; | ||
background-color: shared_input-select-picker.$background-color-normal; | ||
|
||
&:hover { | ||
border-color: shared_input-select-picker.$lime-text-field-outline-color--hovered; | ||
background-color: shared_input-select-picker.$background-color-hovered; | ||
} | ||
|
||
&:focus-within { | ||
border-color: shared_input-select-picker.$lime-text-field-outline-color--focused; | ||
} | ||
} | ||
|
||
&[disabled] { | ||
border-color: transparent; | ||
} | ||
|
||
&:has(legend) { | ||
// In input fields, the `label`s are optional, | ||
// and we use the `legend` to render the `label`. | ||
// This ensures that when or if the label appears, | ||
// the field doesn't visually move down in the DOM. | ||
$_height-of-the-legend: -0.75rem; | ||
margin-top: calc( | ||
(#{$_height-of-the-legend} / 2) + (#{$_thickness-of-the-border} / 2) | ||
); | ||
} | ||
} | ||
|
||
legend { | ||
box-sizing: border-box; | ||
@include mixins.truncate-text; | ||
max-width: 100%; | ||
|
||
color: shared_input-select-picker.$label-color; | ||
font-size: 0.65rem; // `10.4px` similar to MDC's floating label | ||
letter-spacing: var(--mdc-typography-subtitle1-letter-spacing, 0.009375em); | ||
|
||
padding-inline-start: 0.25rem; | ||
padding-inline-end: 0.25rem; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adrianschmidt this might be interesting for you
Why is this a new file, and in located in
style/internal
?Because with some minor CSS magic, you can turn the
<fieldset>
element to something that looks like our the famous MDC input field.The only difference is that we don't get that transition (floating animation) of the label → floating_label.
But also, we don't have to make that complex structure of
![image](https://private-user-images.githubusercontent.com/35954987/325271462-63ce4523-7464-460d-a067-60577a8cd854.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEwNTk1MzMsIm5iZiI6MTcyMTA1OTIzMywicGF0aCI6Ii8zNTk1NDk4Ny8zMjUyNzE0NjItNjNjZTQ1MjMtNzQ2NC00NjBkLWEwNjctNjA1NzdhOGNkODU0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE1VDE2MDAzM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThmMTMxM2ZmOTMyYjRmMjMzMmI0YTIyOWFmNGFlM2M3YmM4ZThiOGJlYzAzZGUwN2UwMzE3N2EyNmMzNjQwOGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.OUspG1aI5Kbo-_8KS_bG2KzzkXGAPU0AT7ZnAIwwlso)
mdc-notched-outline
and handle all the focus/floating related stuff.
My long term plan for us is to get rid of the MDC logic in limel-input-field. I think using
field-set
is a good way out. Which is why I am putting this in a separate file, which we can hopefully reuse later.Semantics and accessibility?
Note
Note that to get a better user interface, I need to use the
legend
to display thelabel
.As far as I can see in online examples, you can have a single input element in a
fieldset
.However, the
fieldset
andlegend
elements are typically used to group together several related form controls and label them with a common theme. So when it comes to semantics and accessibility, we may wonder:fieldset
element, but only putting one single (not several) input fields in it is OK.label
element for that input field, and instead use thelegend
that belongs intact to thefieldset
and displaying the label of the field in the legend is OK?Would these make confusing experiences for users of assistive technologies such as screen readers?
Using a fieldset for a single input field is not semantically incorrect, but it might be overkill and could potentially confuse users of assistive technologies.
The legend element is originally meant to provide a caption for the
fieldset
. Using it as a replacement for a label may not recommended.My own assessment for the current usage (in
limel-text-editor
) is that we are just fine. Firstly, the ProseMirror library has lots of accessibility issues, so this one is really minor, to be honest. Secondly, I feel wrapping complexities and controls of a rich text editor inside afieldset
can still make sense (?)But when/if the day comes that we wanna do the same, when refactoring
limel-input-field
and usefieldset
in there, we should keep in mind that screen readers and other assistive technologies rely on the correct use of HTML elements for proper functionality. Therefore if we still want to use legend instead of label, it might not be correctly associated with the input field by assistive technologies, leading to a confusing user experience.To mitigate these issues, we could consider the following:
Use a label for the input field, even if we're also using a legend. This ensures that the input field has a proper label that can be read by assistive technologies.
If we want to use the legend to display the label for stylistic reasons, we could hide the label visually but still keep it in the HTML. This way, it can be read by screen readers but won't affect our layout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great to me! 👍
Reading your post, I was think exactly this. We can definitely have a visually hidden
label
that is still read by screen readers. We can probably also prevent screen readers from reading out the content of thelegend
element.EDIT: We don't need to make those tweaks now. I meant for later, if and when we make the proposed changes to limel-input-field 👍