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

Add data-dv-value attributes to inline-field-value spans #2498

Open
elliebartling opened this issue Dec 30, 2024 · 0 comments
Open

Add data-dv-value attributes to inline-field-value spans #2498

elliebartling opened this issue Dec 30, 2024 · 0 comments
Labels
feature-request New feature or request.

Comments

@elliebartling
Copy link

Is your feature request related to a problem? Please describe.
I'd love to be able to target different inline fields based on their values, not just their keys. Currently, it is not possible to do so, and CSS does not support selecting based on inner-text.

Describe the solution you'd like
I'd like to add data-dv-value attributes to the inline field spans, so that I can target them with CSS like so:

<span class="dataview inline-field-key" data-dv-key="Status" data-dv-norm-key="status">Status</span>
<span class="dataview inline-field-value" data-dv-key="Status" data-dv-value="Locked">Locked</span>
.dataview.inline-field-value[data-dv-value*="Locked"]::before {
  content: "🔒";
}

.dataview.inline-field-value[data-dv-value*="Unlocked"]::before {
  content: "✨";
}

Describe alternatives you've considered
An alternative that I considered is to just create different keys & set them to "true", but that's a bit messy & requires a lot of manual re-work (e.g., setting locked to false then also unlocked to true).

Additional context
I tried updating the dataview plugin in my own vault to include these lines and it seems to work without issues!

toDOM() {
        // A large part of this method was taken from replaceInlineFields() in src/ui/views/inline-field.tsx.
        // It will be better to extract the common part as a function...
        const renderContainer = createSpan({
            cls: ["dataview", "inline-field"],
        });
        // Block inline fields render the key, parenthesis ones do not.
        if (this.field.wrapping == "[") {
            const key = renderContainer.createSpan({
                cls: ["dataview", "inline-field-key"],
                attr: {
                    "data-dv-key": this.field.key,
                    "data-dv-norm-key": canonicalizeVarName(this.field.key),
                },
            });
            renderCompactMarkdown(this.app, this.field.key, key, this.sourcePath, this.component, true);
            const value = renderContainer.createSpan({
                cls: ["dataview", "inline-field-value"],
                // ✨ New stuff here
                attr: {
                  "data-dv-key": this.field.key,
                  "data-dv-value": this.field.value
              },
            });
            renderValue(this.app, parseInlineValue(this.field.value), value, this.sourcePath, this.component, this.settings, false, undefined, undefined, true);
            this.addKeyClickHandler(key, renderContainer);
            this.addValueClickHandler(value, renderContainer);
        }
        else {
            const value = renderContainer.createSpan({
                cls: ["dataview", "inline-field-standalone-value"],
                // ✨ And also here
                attr: {
                  "data-dv-key": this.field.key,
                  "data-dv-value": this.field.value
              },
            });
            renderValue(this.app, parseInlineValue(this.field.value), value, this.sourcePath, this.component, this.settings, false, undefined, undefined, true);
            this.addValueClickHandler(value, renderContainer);
        }
        return renderContainer;
    }
@elliebartling elliebartling added the feature-request New feature or request. label Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request.
Projects
None yet
Development

No branches or pull requests

1 participant