Skip to content
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

Rendering: field-sizing support for some elements #9903

Merged
merged 7 commits into from
Feb 6, 2024

Conversation

tkent-google
Copy link
Contributor

@tkent-google tkent-google commented Nov 2, 2023

This commit adds the details of field-sizing property behavior for some elements.

This covers:

  • input element as a text entry widget: size attribute is ignored if field-sizing:content
  • input element with number state
  • input element as a file upload control (optional)
  • select element: size attribute is used only for dropdown/listbox switching if field-sizing:content
  • textarea element: cols/rows are ignored if field-sizing:content

This also stops applying "presentational hints" and "user-agent-level style rule" for width and
height properties in order to match to major browser behaviors.

Issue: #6807
Issue: w3c/csswg-drafts#7542

(See WHATWG Working Mode: Changes for more details.)


/infrastructure.html ( diff )
/rendering.html ( diff )

This covers:
 - input element as a text entry widget
    size attribute is ignored if field-sizing:content
 - input element as domain-specific widgets (optional)
 - input element as a file upload control (optional)
 - select element
    size attribute is used only for dropdown/listbox switching if
    field-sizing:content
 - textarea element
    cols/rows are ignored if field-sizing:content

Issue: whatwg#6807
Issue: w3c/csswg-drafts#7542
@domenic domenic requested a review from zcorpan November 2, 2023 06:06
@emilio
Copy link
Contributor

emilio commented Nov 2, 2023

So I have a few concerns about how this interacts with <input>:

  • How does this interact with autofill? I don't think we want to expose the autofilled text length...
  • The interaction with placeholder seems a bit unfortunate? Per the draft, the input would shrink once the placeholder is not visible, which seems weird, and there's no way to prevent, right?

Also, This seems to also affect textarea inline-size which seems a bit surprising, but maybe it's fine?

@tkent-google
Copy link
Contributor Author

  • How does this interact with autofill? I don't think we want to expose the autofilled text length...

Yeah, we should not expose the autofilled text size for a security reason.
How about applying the default size as ever if the control has autofilled text? That is to say, we won't apply field-sizing: content for autofilled controls.

  • The interaction with placeholder seems a bit unfortunate? Per the draft, the input would shrink once the placeholder is not visible, which seems weird, and there's no way to prevent, right?

That's right.
Specifying min-width might be a workaround.

Also, This seems to also affect textarea inline-size which seems a bit surprising, but maybe it's fine?

I think it's fine. Web authors can specify a fixed inline-size even if field-sizing: content.

@emilio
Copy link
Contributor

emilio commented Nov 8, 2023

Yeah, we should not expose the autofilled text size for a security reason. How about applying the default size as ever if the control has autofilled text? That is to say, we won't apply field-sizing: content for autofilled controls.

That seems like it could cause layout issues in websites, but maybe it's fine. In that case the UA stylesheet should probably be extended with input:autofill { field-sizing: auto !important } or so.

  • The interaction with placeholder seems a bit unfortunate? Per the draft, the input would shrink once the placeholder is not visible, which seems weird, and there's no way to prevent, right?

That's right. Specifying min-width might be a workaround.

It's not tho, right? There's no way to specify min-width: <width-of-placeholder> or so...

@tkent-google
Copy link
Contributor Author

Yeah, we should not expose the autofilled text size for a security reason. How about applying the default size as ever if the control has autofilled text? That is to say, we won't apply field-sizing: content for autofilled controls.

That seems like it could cause layout issues in websites, but maybe it's fine. In that case the UA stylesheet should probably be extended with input:autofill { field-sizing: auto !important } or so.

I updated the PR to include input:autofill, select:autofill, textarea:autofill.

  • The interaction with placeholder seems a bit unfortunate? Per the draft, the input would shrink once the placeholder is not visible, which seems weird, and there's no way to prevent, right?

That's right. Specifying min-width might be a workaround.

It's not tho, right? There's no way to specify min-width: <width-of-placeholder> or so...

I supposed to specify a fixed value like <input placeholder="foo" style="min-width: 3ch">.

@emilio
Copy link
Contributor

emilio commented Nov 13, 2023

I supposed to specify a fixed value like <input placeholder="foo" style="min-width: 3ch">.

That only works if the font is monospace tho, right?

source Show resolved Hide resolved
@tkent-google
Copy link
Contributor Author

I supposed to specify a fixed value like <input placeholder="foo" style="min-width: 3ch">.

That only works if the font is monospace tho, right?

Right. It's a workaround, not a perfect solution.
Probably "no-shrink mode" is necessary to resolve this issue. IMO browsers may ship the current feature, and can try to resolve this issue later if many web developers complain about it.

@tkent-google
Copy link
Contributor Author

@zcorpan Would you review this please?

@tkent-google
Copy link
Contributor Author

@annevk , can you review this please?

Copy link
Member

@foolip foolip left a comment

Choose a reason for hiding this comment

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

I've done my best to give editorial review of this. I only read up on the discussion today so I've probably missing some aspects, but I found some issues at least.

source Outdated Show resolved Hide resolved
source Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Outdated Show resolved Hide resolved
Comment on lines +131926 to +131931
<p>If the <span>'field-sizing'</span> property on the element has a <span>computed value</span>
of <span data-x="field-sizing-content">'content'</span>, the <span>inline size</span> is
determined by the text which the element shows. The text is either a
<span data-x="concept-fe-value">value</span> or a short hint specified by the
<code data-x="attr-input-placeholder">placeholder</code> attribute. User agents may take the
text caret size into account in the <span>inline size</span>.</p>
Copy link
Member

Choose a reason for hiding this comment

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

Say here that autofill text or uncommitted writing suggestion must not be considered in this step.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm maybe autofill doesn't need to be mentioned since there's the :autofill UA rule. Should a writing suggestion affect intrinsic size?

Copy link
Member

Choose a reason for hiding this comment

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

See #9065

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I'm not sure about a writing suggestion. If it suggest sensitive text such as credit card numbers, intrinsic size should not depend on it.

Copy link
Member

Choose a reason for hiding this comment

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

So field-sizing would then make writing suggestions invisible (if normally rendered inline)?

cc @sanketj @annevk

Copy link

Choose a reason for hiding this comment

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

User agents may take the text caret size into account

According to the latest changes to Chrome, should the may here be changed to must?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. We can discuss desired interaction if both features were to be added, though.

Can we discuss it in #9065 ?

Anyway my current thought:

  • If a suggestion by the writing suggestion feature is not shown in the page initially (e.g. shown in a popup window) and a user confirms it before committing it to a form control, we don't need to care about a combination of field-sizing and the writing suggestion feature
  • If a suggestion by the writing suggestion feature is shown in a form control without a user confirmation,
    • If the suggestion desn't contain any sensitive information, field-sizing:content should assume the suggestion is a kind of content
    • If the suggestion might contain sensitive information, it should be treated as same as :autofill. i.e. the form control has a fixed intrinsic size.

Copy link
Member

Choose a reason for hiding this comment

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

I didn't realize writing suggestions were still an open issue, I agree then it can be considered as part of that issue. @tkent-google can you comment on that issue so it's not forgotten later?

I'm going to approve this now as I think it looks good, but waiting for @zcorpan to review/merge, since he still has a "changes requested" review from earlier.

Copy link
Member

Choose a reason for hiding this comment

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

Moving to 9065 sounds good, I commented there: #9065 (comment)

@yisibl 's comment above is not addressed I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the latest changes to Chrome, should the may here be changed to must?

I don't want to make it mandatory.

  • Text caret is not defined in CSS specifications AFAIK.
  • Text caret shape is implementation-dependent.
  • Text caret painting is also implementation-dependent. For example, Blink can't paint text caret if the width of content box is zero, but can paint it if the width is greater than zero and it has no space dedicated to the text caret. Other UAs might be able to paint text caret even if the width is zero.

So, it's difficult to define concrete behavior and write tests.

source Outdated Show resolved Hide resolved
source Show resolved Hide resolved
aarongable pushed a commit to chromium/chromium that referenced this pull request Feb 1, 2024
Text caret wasn't visible if the content width is 0px.

The HTML specification will have:
> User agents may take the text caret size into account
whatwg/html#9903

Bug: 1447058, 1523248
Change-Id: Id914795bfac2b09c0abce483e70f4e1e9bba4a77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5252630
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Auto-Submit: Kent Tamura <tkent@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1254905}
@tkent-google
Copy link
Contributor Author

A WPT change is ready: web-platform-tests/wpt#44346

@domenic domenic added topic: rendering addition/proposal New features or enhancements labels Feb 6, 2024
@domenic domenic merged commit ae80157 into whatwg:main Feb 6, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements topic: rendering
Development

Successfully merging this pull request may close these issues.

7 participants