Skip to content

feat(TextInput): add helper util for left trim - #4691

Merged
jschuler merged 22 commits into
patternfly:masterfrom
jenny-s51:iss4637
Aug 24, 2020
Merged

jschuler merged 22 commits into
patternfly:masterfrom
jenny-s51:iss4637

Conversation

@jenny-s51

Copy link
Copy Markdown
Contributor

What: Closes #4637

This is WIP; working on adding this functionality to TextInput.

@jenny-s51
jenny-s51 marked this pull request as draft August 13, 2020 19:43
@patternfly-build

patternfly-build commented Aug 13, 2020 •

Copy link
Copy Markdown
Collaborator

Comment thread packages/react-core/src/helpers/util.ts Outdated
Comment thread packages/react-core/src/helpers/util.ts Outdated
Comment thread packages/react-core/src/components/TextInput/examples/TextInput.md Outdated
@jenny-s51
jenny-s51 requested a review from jschuler August 18, 2020 18:54
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #4691 into master will decrease coverage by 0.22%.
The diff coverage is 20.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4691      +/-   ##
==========================================
- Coverage   52.52%   52.30%   -0.23%     
==========================================
  Files         514      514              
  Lines        8974     9030      +56     
  Branches     3266     3281      +15     
==========================================
+ Hits         4714     4723       +9     
- Misses       3673     3718      +45     
- Partials      587      589       +2     
Flag Coverage Δ
#patternfly4 52.30% <20.33%> (-0.23%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/react-core/src/helpers/util.ts 37.50% <10.00%> (-9.17%) ⬇️
.../react-core/src/components/TextInput/TextInput.tsx 46.34% <31.03%> (-40.33%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ffe4695...5741c9d. Read the comment docs.

@jenny-s51
jenny-s51 marked this pull request as ready for review August 21, 2020 14:43
Comment thread packages/react-core/src/components/TextInput/TextInput.tsx Outdated
@@ -26,7 +26,7 @@ class SimpleTextInput extends React.Component {
const { value } = this.state;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Undo changes to this file

kmcfaul
kmcfaul previously approved these changes Aug 21, 2020

@kmcfaul kmcfaul left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@jschuler

Copy link
Copy Markdown
Contributor

Also, can you add a separate example to TextInput.md instead of modifying the Disabled example?

componentDidMount() {
if (this.props.isLeftTruncated) {
this.handleResize();
window.addEventListener('resize', debounce(this.handleResize, 250));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i just realized that the input box dimensions can change even if there was no window resize, for example if a sidebar is opened. Perhaps we should look at something like the ResizeObserver instead
https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver
Example implementation
https://github.com/ZeeCoder/use-resize-observer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Opened followup issue for next milestone here #4710 @jenny-s51 @tlabaj

isRequired,
isDisabled,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onFocus,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you'll want to extract isLeftTruncated here even though it is not used in the returned JSX so it doesn't end up in the DOM. Can combine the 3 unused props in this way

/* eslint-disable @typescript-eslint/no-unused-vars */
      isLeftTruncated,
      onFocus,
      onBlur,
      /* eslint-enable @typescript-eslint/no-unused-vars */

@mcarrano mcarrano left a comment

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.

So how would this work for different components? I can see it implemented for the Text input, but what if I wanted on a different component like a Table or a Select? Would it need to be applied on a per component basis or is there a general way to do this? Also, we typically present a tooltip for truncated text strings, not sure if that would be part of the component demo or not.

@jenny-s51 jenny-s51 changed the title feat(text): add helper util for left trim feat(TextInput): add helper util for left trim Aug 21, 2020
@jschuler

Copy link
Copy Markdown
Contributor

@mcarrano with this PR there will be some utility functions to make it easier to implement for others, but we'll have to add and test it per component.
Adding tooltip would be possible but the examples already didn't have it to begin with (e.g. if you type more text into the first input example until there is overflow with the ellipsis on the right there is no tooltip at the moment).
Also it is not quite clear to me if there should be tooltips on enabled inputs since you can see and edit the whole string once you focus on it. I can see it being more useful for disabled inputs, but that might take more work as well since disabled elements generally don't emit events.

@mcarrano

Copy link
Copy Markdown
Member

Good points @jschuler . Are the utility functions documented somewhere? If I were a developer wanting to apply this on my own to a different component. Would it be obvious how to do that or would they need to wait for us to add it as a new library update?

@jschuler

jschuler commented Aug 21, 2020 •

Copy link
Copy Markdown
Contributor

@mcarrano Currently they are only documented in code! But we do export all the functions out so consumers could use them if they wanted to. I think the utility function would be pretty simple to use!

import { trimLeft } from '@patternfly/react-core'
...
const myElement = document.getElementById("my-input");
trimLeft(myElement, "The string which should be truncated on the left if needed");

@tlabaj tlabaj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you just update demo app and integration test please.

jschuler
jschuler previously approved these changes Aug 22, 2020

@jschuler jschuler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@jschuler

jschuler commented Aug 24, 2020 •

Copy link
Copy Markdown
Contributor

LGTM, I noticed a bug where if you remove isDisabled / isRead and try to type into the textbox it won't let you! But it is not something from this PR, it already exists since the last release at least. But we should fix this @tlabaj

Nevermind, turns out the value has to be changed via state

export const trimLeft = (node: HTMLElement, value: string) => {
const availableWidth = innerDimensions(node).width;
let newValue = value;
if (getTextWidth(value, node) > availableWidth) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just one bug here, can you add an else condition to this if. Noticed that if you just a little overflow and you expand the textbox until the whole text should fit again, it won't restore the value

 else {
    if ((node as HTMLInputElement).value) {
      (node as HTMLInputElement).value = value;
    } else {
      node.innerText = value;
    }
  }

@jenny-s51
jenny-s51 requested a review from jschuler August 24, 2020 15:14

@tlabaj tlabaj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@jschuler
jschuler merged commit 44dba19 into patternfly:master Aug 24, 2020
@patternfly-build

Copy link
Copy Markdown
Collaborator

Your changes have been released in:

Thanks for your contribution! 🎉

@jenny-s51
jenny-s51 deleted the iss4637 branch August 24, 2020 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Truncate the left side content

7 participants