Skip to content

Access targets during initialization #129

Closed

Description

@lcmen

Hey!
First of all, sorry for using GitHub issues for asking questions but not sure what's the best place to ask for help. I want to ask what's the best way to access targets during the initialization process (according to docs,connectedCallback might be too early to query element from the DOM)? Let's say I'd like to setup / start dropzone on a specific target when component is initialized. When / how should I do it?

Activity

  1. lcmen commented on Mar 27, 2021

    @lcmen
    ContributorAuthor

    Actually I've found html-parsed-element which addresses this problem (it's a nice abstraction over MutationObserver). Unfortunately, it does not allow to override connectedCallback via regular operator assignment (used by @controller decorator), so I've created a PR to fix it. Hopefully it gets merged, so we can access targets in the parsedCallback like this:

    import HTMLParsedElement from 'html-parsed-element';
    import { controller, attr, target } from '@github/catalyst'
    
    @controller
    export default class TextEditorElement extends HTMLParsedElement {
      @target area: HTMLInputElement
    
      parsedCallback() {
        this.area.value = 'Hello World!'
      }
    }

    PS. TypeScript might complain about HTMLParsedElement compatilbity with HTMLElement (Argument of type 'typeof TextEditorElement' is not assignable to parameter of type 'CustomElement'. Type 'TextEditorElement' is missing the following properties from type 'HTMLElement': accessKey, accessKeyLabel, autocapitalize, dir, and 234 more.).

  2. lcmen commented on Mar 27, 2021

    @lcmen
    ContributorAuthor

    PR got merged, and new version has been released so parsedCallback can be used with catalyst to initialize targets as shown above.

    Should I add such info to the guides?

  3. locked and limited conversation to collaborators on Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions