klaro-org / klaro-js

Klaro Privacy Manager. An open-source, privacy-friendly & compliant consent manager for your website.
https://klaro.org
Other
1.19k stars 253 forks source link

Cannot read properties of undefined (reading 'focus') #497

Closed bojko91 closed 6 months ago

bojko91 commented 7 months ago

Klaro Config

//deffault mustConsent: false, mustConsent: true,

I clone repository to my server. Just want to add BG language and make some changes. Run commands npm install, after that make add a language and run npm run-script make-dev

When i set mustConsent to true when put script in the site, get an error "Uncaught TypeError: Cannot read properties of undefined (reading 'focus')".

return t = a, r = [{ key: "componentDidMount", value: function() { **this.consentModalRef.focus()** } }, { key: "render", value: function() {

When im using klaro.js from web site doesn`t have this problem. When i look up over the file this option is missing at all

The problem is caused from here but didnt know how to fix it.

export default class ConsentModal extends React.Component {
    componentDidMount() {
        this.consentModalRef.focus();
    }

    render() {
        const {
            hide,
            confirming,
            saveAndHide,
            acceptAndHide,
            declineAndHide,
            config,
            manager,
            lang,
            t,
        } = this.props;
        const { embedded } = config;
        const groupByPurpose =
            config.groupByPurpose !== undefined ? config.groupByPurpose : true;

        let closeLink;
        if (!config.mustConsent) {
            closeLink = (
                <button
                    title={t(['close'])}
                    aria-label={t(['close'])}
                    className="hide"
                    type="button"
                    onClick={hide}
                    tabIndex="0"
                    ref={(div) => {
                        this.consentModalRef = div;
                    }}
                >
                    <Close t={t} />
                </button>
            );
        }
rmelchner commented 6 months ago

@bojko91 was fixed in https://github.com/klaro-org/klaro-js/pull/499 can you try if it works for you?

bojko91 commented 6 months ago

@bojko91 was fixed in #499 can you try if it works for you?

Yeahhh its fixed, THANKS a lot! <3