Skip to content

Commit

Permalink
Fix textarea sizing in datapoint editor.
Browse files Browse the repository at this point in the history
Textareas (.entry-long) now flex-grow to fill available space. The previous content-based height is now applied to min-height, so that they don't become too small before scrolling is triggered.

This should greatly improve the experience of using LIT with longer text.

Also fix a minor issue with text wrapping in footer buttons.

PiperOrigin-RevId: 607815280
  • Loading branch information
iftenney authored and LIT team committed Feb 16, 2024
1 parent 000c844 commit a758f98
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
33 changes: 29 additions & 4 deletions lit_nlp/client/modules/datapoint_editor_module.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ select.dropdown {
min-width: 50px;
}

#edit-table {
display: flex;
flex-direction: column;
height: 100%;
}

.entry {
align-items: center;
box-sizing: border-box;
Expand All @@ -144,6 +150,15 @@ select.dropdown {
border-radius: 4px;
}

.entry-long {
flex-grow: 1;
flex-basis: 100%;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
flex-flow: column;
}

.entry-edited {
background: var(--lit-bric-50);
}
Expand All @@ -154,12 +169,23 @@ select.dropdown {
justify-content: flex-end;
}

.entry-content-long {
.entry-medium .entry-content {
flex-grow: 1;
flex-basis: 100%;
max-width: max(50%, 500px);
}

.entry-long .entry-content {
flex-direction: column;
justify-content: flex-start;
height: 100%;
width: 100%;
}

.entry-long .entry-content textarea {
height: 100%;
}

.entry-content.left-align {
.entry-left-align .entry-content {
justify-content: flex-start;
}

Expand All @@ -170,7 +196,6 @@ input {

textarea {
resize: vertical;
height: 100px;
font-family: 'Roboto', sans;
line-height: 18px;
color: var(--lit-gray-800);
Expand Down
31 changes: 16 additions & 15 deletions lit_nlp/client/modules/datapoint_editor_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export class DatapointEditorModule extends LitModule {
</button>
`;
const compareButton = html`
<button id="compare" class='hairline-button'
<button id="compare" class='hairline-button' style="text-wrap: nowrap;"
@click=${onClickCompare} ?disabled="${!compareEnabled}">
Add and compare
</button>
Expand Down Expand Up @@ -524,7 +524,7 @@ export class DatapointEditorModule extends LitModule {
const errorInputClasses = renderError ? 'error-input' : '';
const errorIconClasses = renderError ? 'error-icon' : '';

const inputStyle = {'height': this.inputHeights[key]};
const inputStyle = {'min-height': this.inputHeights[key]};
// Render a multi-line text input.
const renderFreeformInput = () => html`
<textarea
Expand Down Expand Up @@ -612,25 +612,29 @@ export class DatapointEditorModule extends LitModule {
!(fieldSpec instanceof Embeddings));
};

let renderInput = renderFreeformInput; // default: free text
const entryContentClasses = {
'entry-content': true,
'entry-content-long': false,
'left-align': false,
const entryClasses = {
'entry': true,
'entry-edited': this.dataEdits[key] !== undefined,
'entry-medium': false,
'entry-long': false,
'entry-left-align': false,
};

let renderInput = renderFreeformInput; // default: free text
const fieldSpec = this.appState.currentDatasetSpec[key];
const {vocab} = fieldSpec as LitTypeWithVocab;
if (vocab != null && !(fieldSpec instanceof SparseMultilabel)) {
renderInput = () => renderCategoricalInput(vocab);
} else if (this.groupService.categoricalFeatureNames.includes(key)) {
renderInput = renderShortformInput;
entryClasses['entry-medium'] = true;
} else if (this.groupService.numericalFeatureNames.includes(key)) {
renderInput = renderNumericInput;
} else if (isLitSubtype(
fieldSpec, [Tokens, SequenceTags, SparseMultilabel])) {
renderInput = renderTokensInput;
entryContentClasses['entry-content-long'] = true;
entryContentClasses['left-align'] = true;
entryClasses['entry-long'] = true;
entryClasses['entry-left-align'] = true;
} else if (fieldSpec instanceof Embeddings) {
renderInput = renderEmbeddingsNonEditable;
} else if (fieldSpec instanceof SpanLabels) {
Expand All @@ -644,7 +648,7 @@ export class DatapointEditorModule extends LitModule {
} else if (fieldSpec instanceof BooleanLitType) {
renderInput = renderBoolean;
} else {
entryContentClasses['entry-content-long'] = true;
entryClasses['entry-long'] = true;
}

// Shift + enter creates a newline; enter alone creates a new datapoint.
Expand Down Expand Up @@ -689,14 +693,11 @@ export class DatapointEditorModule extends LitModule {
</a>`;
}

const entryClasses = classMap(
{'entry': true, 'entry-edited': this.dataEdits[key] !== undefined});

// Note the "." before "value" in the template below - this is to ensure
// the value gets set by the template.
// clang-format off
return html`
<div class=${entryClasses}
<div class=${classMap(entryClasses)}
@keyup=${(e: KeyboardEvent) => {onKeyUp(e);}}
@keydown=${(e: KeyboardEvent) => {onKeyDown(e);}}
>
Expand All @@ -709,7 +710,7 @@ export class DatapointEditorModule extends LitModule {
</mwc-icon>
</lit-tooltip>
</div>
<div class=${classMap(entryContentClasses)}>
<div class='entry-content'>
${renderInput()}
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions lit_nlp/client/modules/embeddings_module.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

.module-footer > * { min-width: 0; }

.selected-nearest-button {
text-wrap: nowrap;
}

.selected-nearest-button:disabled {
pointer-events: auto;
}
Expand Down

0 comments on commit a758f98

Please sign in to comment.